Better checking of the index operand (#1992)

Fixes https://crbug.com/897069

* Code previously assumed the index instruction had a type
* Added a test to reproduce
This commit is contained in:
alan-baker 2018-10-22 08:47:56 -04:00 committed by GitHub
parent 6e85d1a6fc
commit 89b8e238eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -148,8 +148,8 @@ spv_result_t ValidateVectorExtractDynamic(ValidationState_t& _,
<< "Expected Vector component type to be equal to Result Type";
}
const uint32_t index_type = _.GetOperandTypeId(inst, 3);
if (!_.IsIntScalarType(index_type)) {
const auto index = _.FindDef(inst->GetOperandAs<uint32_t>(3));
if (!index || index->type_id() == 0 || !_.IsIntScalarType(index->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Index to be int scalar";
}

View File

@ -1469,6 +1469,30 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateComposites, ExtractDynamicLabelIndex) {
const std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%void = OpTypeVoid
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%void_fn = OpTypeFunction %void
%float_0 = OpConstant %float 0
%v4float_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
%func = OpFunction %void None %void_fn
%1 = OpLabel
%ex = OpVectorExtractDynamic %float %v4float_0 %1
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Expected Index to be int scalar"));
}
} // namespace
} // namespace val
} // namespace spvtools