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

Closed
github-bot wants to merge 1 commit from gh-pr/300/head into gh-pr/300/base
Owner

@⁠SkippySteve on GitHub · 2026-11-24 02:09 UTC · original
SkippySteve/dxil-reject-tests → main · +86 −0 · 1 files · 1 commits · closed without merging

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
**@⁠SkippySteve** on GitHub · 2026-11-24 02:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/300) `SkippySteve/dxil-reject-tests` → `main` · +86 −0 · 1 files · 1 commits · closed without merging `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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:28 +00:00
github-bot closed this pull request 2026-11-26 03:58:28 +00:00
Author
Owner

@⁠SkippySteve on GitHub · 2026-11-24 02:29 UTC · original

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

**@⁠SkippySteve** on GitHub · 2026-11-24 02:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/300#issuecomment-7120196919) superseded by #326 (combined shader DX/parser robustness)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!300
No description provided.