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

Closed
SkippySteve wants to merge 1 commit from upstream-pr/300 into main
SkippySteve commented 2026-11-24 02:09:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T02:09:55Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573006874 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/300). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T02:09:55Z. --- `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
upstream-sync closed this pull request 2026-11-24 06:52:18 +00:00
SkippySteve commented 2026-11-24 06:55:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T02:29:28Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120196919 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/300#issuecomment-7120196919). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T02:29:28Z. --- superseded by #326 (combined shader DX/parser robustness)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!300
No description provided.