Error for invalid location type (#5249)

Fixes https://crbug.com/oss-fuzz/56754

* When checking locations, produce an error if the type cannot be
  assigned a location
This commit is contained in:
alan-baker 2023-05-30 09:08:09 -04:00 committed by GitHub
parent 673d8bfcb6
commit cf62673e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 6 deletions

View File

@ -174,7 +174,8 @@ spv_result_t NumConsumedLocations(ValidationState_t& _, const Instruction* type,
break;
}
default:
break;
return _.diag(SPV_ERROR_INVALID_DATA, type)
<< "Invalid type to assign a location";
}
return SPV_SUCCESS;
@ -363,12 +364,12 @@ spv_result_t GetLocationsForVariable(
sub_type = _.FindDef(sub_type_id);
}
for (uint32_t array_idx = 0; array_idx < array_size; ++array_idx) {
uint32_t num_locations = 0;
if (auto error = NumConsumedLocations(_, sub_type, &num_locations))
return error;
uint32_t num_locations = 0;
if (auto error = NumConsumedLocations(_, sub_type, &num_locations))
return error;
uint32_t num_components = NumConsumedComponents(_, sub_type);
uint32_t num_components = NumConsumedComponents(_, sub_type);
for (uint32_t array_idx = 0; array_idx < array_size; ++array_idx) {
uint32_t array_location = location + (num_locations * array_idx);
uint32_t start = array_location * 4;
if (kMaxLocations <= start) {

View File

@ -1570,6 +1570,35 @@ OpFunctionEnd
"Interface struct has no Block decoration but has BuiltIn members."));
}
TEST_F(ValidateInterfacesTest, InvalidLocationTypePointer) {
const std::string text = R"(
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Vertex %1 "Aiqn0" %2 %3
OpDecorate %2 Location 0
%void = OpTypeVoid
%5 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Private_void = OpTypePointer Private %void
%uint = OpTypeInt 32 0
%uint_4278132784 = OpConstant %uint 4278132784
%_arr__ptr_Private_void_uint_4278132784 = OpTypeArray %_ptr_Private_void %uint_4278132784
%_ptr_Output__arr__ptr_Private_void_uint_4278132784 = OpTypePointer Output %_arr__ptr_Private_void_uint_4278132784
%2 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
%_ptr_Output__ptr_Private_void = OpTypePointer Output %_ptr_Private_void
%3 = OpVariable %_ptr_Output__arr__ptr_Private_void_uint_4278132784 Output
%1 = OpFunction %void None %5
%15 = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(text, SPV_ENV_VULKAN_1_1);
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Invalid type to assign a location"));
}
} // namespace
} // namespace val
} // namespace spvtools