Skip to content

Error handling for malformed SPIRV input#3900

Open
maarquitos14 wants to merge 1 commit into
KhronosGroup:mainfrom
maarquitos14:maronas/fix-entry-crash
Open

Error handling for malformed SPIRV input#3900
maarquitos14 wants to merge 1 commit into
KhronosGroup:mainfrom
maarquitos14:maronas/fix-entry-crash

Conversation

@maarquitos14

@maarquitos14 maarquitos14 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Further hardening of the translator against malformed input to prevent crashes. Specifically, this PR:

  • Reports an error and invalidates module in SPIRVFunction::decode() for opcodes that don't belong in function scope.
  • Adds null check with module invalidation and early exit after Decoder.getEntry() in SPIRVFunction::decodeBB() because it can return nullptr and it was otherwise dereferenced down the line.
  • Reports an error and invalidates module for unknown extended instruction set IDs.
  • Reports an error and invalidates module for truncated instructions.

5 new lit tests are added that were crashing before this patch. These new tests are a bit special, they need to feed deliberately malformed SPIR-V to the translator, including opcodes that don't exist, instructions in the wrong scope or truncated streams. Since spirv-as normally validates its input, the tests use its !<integer> syntax to inject raw 32-bit words directly into the binary output, bypassing validation. For example, !75535 emits the raw word (1<<16)|9999, which encodes a single-word instruction with unknown opcode 9999. Care must be taken with placement: ! words after variadic instructions (like OpTypeFunction) get absorbed as extra operands rather than emitted as standalone instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant