Check for limits when setting values from hw config string.

Related-To: NEO-3841

Change-Id: I80001a1bc25ae839578b9ca92fd7b32ac664ed6e
Signed-off-by: Pawel Cieslak <pawel.cieslak@intel.com>
This commit is contained in:
Pawel Cieslak 2019-11-21 12:43:58 +01:00 committed by sys_ocldev
parent 7727cb230a
commit f5b2110ac7
2 changed files with 34 additions and 2 deletions

View File

@ -64,16 +64,33 @@ bool setHwInfoValuesFromConfigString(const std::string &hwInfoConfig, HardwareIn
return false;
}
uint32_t sliceCount = static_cast<uint32_t>(std::stoul(hwInfoConfig.substr(0, currPos)));
if (sliceCount > std::numeric_limits<uint16_t>::max()) {
return false;
}
size_t prevPos = currPos + 1;
currPos = hwInfoConfig.find('x', prevPos);
if (currPos == std::string::npos) {
return false;
}
uint32_t subSliceCount = sliceCount * static_cast<uint32_t>(std::stoul(hwInfoConfig.substr(prevPos, currPos)));
uint32_t subSlicePerSliceCount = static_cast<uint32_t>(std::stoul(hwInfoConfig.substr(prevPos, currPos)));
if (subSlicePerSliceCount > std::numeric_limits<uint16_t>::max()) {
return false;
}
uint32_t subSliceCount = subSlicePerSliceCount * sliceCount;
if (subSliceCount > std::numeric_limits<uint16_t>::max()) {
return false;
}
prevPos = currPos + 1;
uint32_t euCount = subSliceCount * static_cast<uint32_t>(std::stoul(hwInfoConfig.substr(prevPos, std::string::npos)));
uint32_t euPerSubSliceCount = static_cast<uint32_t>(std::stoul(hwInfoConfig.substr(prevPos, std::string::npos)));
if (euPerSubSliceCount > std::numeric_limits<uint16_t>::max()) {
return false;
}
uint32_t euCount = euPerSubSliceCount * subSliceCount;
if (euCount > std::numeric_limits<uint16_t>::max()) {
return false;
}
hwInfoIn.gtSystemInfo.SliceCount = sliceCount;
hwInfoIn.gtSystemInfo.SubSliceCount = subSliceCount;

View File

@ -44,4 +44,19 @@ TEST_F(HwInfoConfigTest, givenInvalidHwInfoSetHwInfoValuesFromConfigString) {
success = setHwInfoValuesFromConfigString("1x3", outHwInfo);
EXPECT_FALSE(success);
success = setHwInfoValuesFromConfigString("65536x3x8", outHwInfo);
EXPECT_FALSE(success);
success = setHwInfoValuesFromConfigString("1x65536x8", outHwInfo);
EXPECT_FALSE(success);
success = setHwInfoValuesFromConfigString("1x3x65536", outHwInfo);
EXPECT_FALSE(success);
success = setHwInfoValuesFromConfigString("65535x65535x8", outHwInfo);
EXPECT_FALSE(success);
success = setHwInfoValuesFromConfigString("1x65535x65535", outHwInfo);
EXPECT_FALSE(success);
}