Fuzz the parsers inside cargo test; a damaged shader operand no longer panics #475

Open
github-bot wants to merge 1 commit from github-bot/gh-475 into a-publier AGit
Owner

@⁠booomxd on GitHub · 2026-11-27 04:56 UTC · original
booomxd:fuzz-parsers → a-publier · +747 −1 · 11 files · 1 commits · open

Requested by booomxd · project thread

What

The parsers read bytes nobody vouches for: the user's dump, its import libraries, its shader containers and their programs. A malformed field has to come back as an error, never as a panic. Until now only BCPack and XMA had noise tests.

  • victory_core::fuzz is a small seeded mutator. It sets known fields to edge values, nudges them, cuts the input short, copies runs over other runs and appends bytes. It runs each target on 4,096 damaged cases of an input that the test builds itself, so no game data is read (rule #1) and CI runs it unchanged. A failure names its target, seed and case. VICTORY_FUZZ_CASES and VICTORY_FUZZ_SEED let a developer search longer.
  • Targets:
    • PE32+ images: one synthetic image with imports by name and by ordinal, delay imports, an export, TLS callbacks and a CodeView record. Accepted images are also checked against their own bounds.
    • COFF import libraries.
    • Shader containers, down to the XDAT index, XBCH, FSSM records and decoding of the native code.
    • Every stage of translating a compute program: spill::build, structure, resource::track, io::raise and emit.

Bug found

In ir.rs, the search for parked scalars kept one flag per scalar code below 128 (used: [bool; 128]) and indexed it with any code an operand named. A damaged word naming code 255 therefore caused an index out of bounds, which took the run down. The flags now cover all 256 codes, the same size as the arrays beside them. Only codes below 124 are ever read back, so translations of valid programs don't change. The failing case is kept as the regression test an_operand_past_the_scalars_is_no_panic, which fails without the fix and passes with it.

Testing

  • These run in the cloud on Linux, because none of the targets need a GPU: cargo test -p victory-core -p victory-pe -p victory-shader --lib. The new tests pass. The four existing victory-pe tests that parse the test executable itself expect a Windows PE, so they fail on Linux as before.
  • Release builds ran 30 million cases of the translation target with the CI seed, plus 10 million cases of each target with each of seeds 1, 2 and 3. Nothing failed after the fix.
  • On the Windows target: cargo clippy --all-targets -D warnings passes, with and without --all-features, for the three crates.
  • cargo xtask policy passes.
  • The new code is rustfmt-clean, and no existing code was reformatted.
  • The full CI ran on a fork (clippy, default tests, diagnostics tests on Windows) and passed: https://github.com/booomxd/VIctory-Belobug-AMD/pull/1
**@⁠booomxd** on GitHub · 2026-11-27 04:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/475) `booomxd:fuzz-parsers` → `a-publier` · +747 −1 · 11 files · 1 commits · open <!-- claude-projects-attribution: {"github_login":"booomxd"} --> _Requested by **booomxd** · [project thread](https://claude.ai/code/project/chan_01NvE3hD6T4Zd6H1B79jToHo?thread=cmsg_01NvE3hD6T4Zd6H1B79jToHoVQt8NTo4LQhuh5hSf299Ar)_ ## What The parsers read bytes nobody vouches for: the user's dump, its import libraries, its shader containers and their programs. A malformed field has to come back as an error, never as a panic. Until now only BCPack and XMA had noise tests. - **`victory_core::fuzz`** is a small seeded mutator. It sets known fields to edge values, nudges them, cuts the input short, copies runs over other runs and appends bytes. It runs each target on 4,096 damaged cases of an input that the test builds itself, so no game data is read (rule #1) and CI runs it unchanged. A failure names its target, seed and case. `VICTORY_FUZZ_CASES` and `VICTORY_FUZZ_SEED` let a developer search longer. - **Targets:** - PE32+ images: one synthetic image with imports by name and by ordinal, delay imports, an export, TLS callbacks and a CodeView record. Accepted images are also checked against their own bounds. - COFF import libraries. - Shader containers, down to the XDAT index, XBCH, FSSM records and decoding of the native code. - Every stage of translating a compute program: `spill::build`, `structure`, `resource::track`, `io::raise` and `emit`. ## Bug found In `ir.rs`, the search for parked scalars kept one flag per scalar code below 128 (`used: [bool; 128]`) and indexed it with any code an operand named. A damaged word naming code 255 therefore caused an index out of bounds, which took the run down. The flags now cover all 256 codes, the same size as the arrays beside them. Only codes below 124 are ever read back, so translations of valid programs don't change. The failing case is kept as the regression test `an_operand_past_the_scalars_is_no_panic`, which fails without the fix and passes with it. ## Testing - These run in the cloud on Linux, because none of the targets need a GPU: `cargo test -p victory-core -p victory-pe -p victory-shader --lib`. The new tests pass. The four existing `victory-pe` tests that parse the test executable itself expect a Windows PE, so they fail on Linux as before. - Release builds ran 30 million cases of the translation target with the CI seed, plus 10 million cases of each target with each of seeds 1, 2 and 3. Nothing failed after the fix. - On the Windows target: `cargo clippy --all-targets -D warnings` passes, with and without `--all-features`, for the three crates. - `cargo xtask policy` passes. - The new code is rustfmt-clean, and no existing code was reformatted. - The full CI ran on a fork (clippy, default tests, diagnostics tests on Windows) and passed: https://github.com/booomxd/VIctory-Belobug-AMD/pull/1
The parsers read bytes nobody vouches for: the user's dump, its import
libraries, its shader containers and their programs. A malformed field
must be an error, never a panic. victory-core gains `fuzz`: a seeded
mutator (edge values on known fields, nudges, cuts, copied runs,
appended bytes) that runs each target on 4,096 damaged cases of an
input the test builds itself, so no game data is read and CI runs it
as it is. A failure names its target, seed and case.

Targets: PE32+ images (one synthetic image with imports, delay
imports, an export, TLS callbacks and a CodeView record), COFF import
libraries, shader containers down to the native programs and their
decoding, and every stage of the translation of a compute program
(spill, structure, resources, I/O, emit). VICTORY_FUZZ_CASES and
VICTORY_FUZZ_SEED let a developer search longer.

The translation target found one panic: the search for parked scalars
in ir.rs kept a flag per scalar code below 128 and indexed it with any
code an operand named, so a damaged word naming code 255 was an index
out of bounds that took the run down. The flags now cover all 256
codes; the case is kept as a regression test. 30 million more cases
of each target found nothing else.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:58:48 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 05:38 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At 3175f72: victory-shader 307 passed, 0 failed, 4 ignored (the fuzz tests included); victory-core 17 passed; victory-pe 39 passed.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 05:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/475#issuecomment-7210806250) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `3175f72`: `victory-shader` 307 passed, 0 failed, 4 ignored (the fuzz tests included); `victory-core` 17 passed; `victory-pe` 39 passed. AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/475/head:github-bot/gh-475'
git switch 'github-bot/gh-475'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-475'
git switch 'github-bot/gh-475'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-475'
git switch 'github-bot/gh-475'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-475'
git switch 'a-publier'
git merge --squash 'github-bot/gh-475'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-475'
git switch 'a-publier'
git merge 'github-bot/gh-475'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.