Conversation
dneto0
left a comment
There was a problem hiding this comment.
This should get a unit test also.
shaderc_assemble_into_spv() leaves output_data_ null when assembly fails, but GetBytes() unconditionally dereferences it, crashing glslc, the C API (shaderc_result_get_bytes), and the C++ API (cbegin/cend) on any invalid .spvasm input. Check output_data_ before dereferencing.
38726c0 to
9495460
Compare
I've added unit tests. And rebased on top of #1603 |
|
Thanks @dneto0 — appreciate the review, and for taking the fix further. Hardening all the result getters against a null result object plus the NullResultObj and GetBytes* tests is a more complete fix than my original change, and the rebase on #1603 is appreciated. |
Fixes #1597
shaderc_assemble_into_spv()leavesoutput_data_null when assembly fails, butGetBytes()unconditionally dereferences it, crashingglslc, the C API (shaderc_result_get_bytes), and the C++ API (cbegin()/cend()) on any invalid.spvasminput.This adds a null check before the dereference. Verified: invalid assembly now errors gracefully (exit 1 with an assembly error message) instead of segfaulting; valid assembly still compiles; C API returns
nullptron failure.Unit test added (3cbbe7a):
AssembleStringTest.FailedAssemblyGetBytesIsNullasserts that a failed assembly result has null bytes and zero length. Without the fix the test crashes with a null pointer dereference (SIGSEGV); with the fix it passes. Full test suite: 151 tests inshaderc_test, 126 inshaderc_cpp_test, all passing.Reported via Google OSS VRP (g.co/vulnz).