Skip to content

Commit 891df4c

Browse files
authored
Fix array length validation (KhronosGroup#6777)
Fixes https://crbug.com/oss-fuzz/529845250 * Fix a segfault from nullptr deref when an operand with no type id is passed as the pointer operand
1 parent 114d39f commit 891df4c

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

source/val/validate_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ spv_result_t ValidateArrayLength(ValidationState_t& state,
24332433
return state.diag(SPV_ERROR_INVALID_ID, inst)
24342434
<< "Pointer must be an untyped pointer object";
24352435
}
2436-
} else if (pointer_ty->opcode() != spv::Op::OpTypePointer) {
2436+
} else if (!pointer_ty || pointer_ty->opcode() != spv::Op::OpTypePointer) {
24372437
return state.diag(SPV_ERROR_INVALID_ID, inst)
24382438
<< "The Structure's type in Op" << spvOpcodeString(opcode)
24392439
<< " <id> " << state.getIdName(inst->id())

test/val/val_memory_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11223,6 +11223,29 @@ OpFunctionEnd
1122311223
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
1122411224
}
1122511225

11226+
TEST_F(ValidateMemory, ArrayLength_BadPointer) {
11227+
std::string spirv = R"(
11228+
OpCapability ClipDistance
11229+
%1 = OpExtInstImport "GLSL.std.450"
11230+
OpMemoryModel Logical GLSL450
11231+
OpName %2097184 "pointer"
11232+
%void = OpTypeVoid
11233+
%6 = OpTypeFunction %void
11234+
%uint = OpTypeInt 32 0
11235+
%8224 = OpFunction %void None %6
11236+
%65312 = OpLabel
11237+
%2097184 = OpArrayLength %uint %1 538976288
11238+
OpUnreachable
11239+
OpFunctionEnd
11240+
)";
11241+
11242+
CompileSuccessfully(spirv);
11243+
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
11244+
EXPECT_THAT(getDiagnosticString(),
11245+
HasSubstr("The Structure's type in OpArrayLength <id> "
11246+
"'2[%pointer]' must be a pointer to an OpTypeStruct"));
11247+
}
11248+
1122611249
} // namespace
1122711250
} // namespace val
1122811251
} // namespace spvtools

0 commit comments

Comments
 (0)