Skip to content

Shader tests: cover each way a DXIL program header is refused - #300

Closed
SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/dxil-reject-tests
Closed

SkippySteve wants to merge 1 commit into
Marvisak:mainfrom
SkippySteve:SkippySteve/dxil-reject-tests

Conversation

@SkippySteve

Copy link
Copy Markdown

DxilProgram::parse (crates/victory-shader/src/dxil.rs) can refuse a program in five ways: a size the part cannot hold, a missing DXIL magic, bitcode out of bounds, no LLVM magic, and a bitcode offset inside the header. It also cuts the part down to the program's own size before reading the trailer. The tests only reached the LLVM-magic case.

This adds synthetic-header tests for:

  • a declared size larger than the part, smaller than the 24-byte header, and u32::MAX dwords (the checked_mul path), plus a truncated header
  • DXBC where DXIL should be
  • bitcode length or offset past the program's end
  • an offset of 4 with LLVM's magic placed in the version field. Only the offset check stops the header from being read as bitcode here.
  • bytes padded after the program, which must not become a trailer (an xbop there would otherwise flag a PC program as Xbox)
  • an unknown program kind, which is kept as ShaderKind::Unknown and not refused

Each rejection test checks its exact Malformed message, so a check that moves or merges with another shows up. I checked that the tests catch real regressions: dropping &part[..size] and the s >= 24 bound makes two of the new tests fail.

The change is tests only, with no code changes. Everything is built from synthetic bytes, with no shader or game data.

Testing (Linux, x86_64-unknown-linux-gnu):

  • cargo test -p victory-shader: 62 passed
  • cargo clippy -p victory-shader --tests: only the constant_color dead-code warning that main already has
  • cargo fmt --check: clean

DxilProgram::parse has five rejections (program size, DXIL magic, bitcode
bounds, LLVM magic, bitcode offset) and trims a part to the program's own
size before reading the trailer, but the tests only reached the LLVM-magic
rejection. Synthetic headers now hit each one by name, check that padding
after the program is not taken for an Xbox trailer, and that an unknown
program kind is kept rather than refused.

Tests only; runs on any host.
@SkippySteve

Copy link
Copy Markdown
Author

superseded by #326 (combined shader DX/parser robustness)

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