Formats: add cargo-fuzz targets for the BCPack and XMA decoders #3324

Open
github-bot wants to merge 2 commits from github-bot/gh-3324 into main AGit
Owner

@⁠gabrielvbraga on GitHub · 2026-11-26 18:07 UTC · original
gabrielvbraga:fuzz-formats → main · +252 −0 · 7 files · 2 commits · open

Closes #3311.

Adds a standalone fuzz/ crate with three cargo-fuzz targets for victory-formats:

  • bcpack_tables: Tables::parse on raw bytes and on the shipped tables with fuzzer-chosen bytes overwritten, then decode with any tables that still parse.
  • bcpack_decode: decode for every supported BC format (1, 3, 4, 5, 6, 7) with the shipped tables.
  • xma_frames: packet, read_frame (packet walk and arbitrary bit offsets) and Decoder::decode / flush.

The crate has its own [workspace], so the main build, tests, CI and rust-toolchain.toml are unaffected; nightly is only needed to run it. No game data, corpora or binaries are committed. New dependency: libfuzzer-sys (MIT/Apache-2.0, libFuzzer under Apache-2.0 with LLVM exception), used only in this crate. fuzz/README.md explains how to run it and turn a crash into a regression test.

Findings

  • bcpack_tables independently found the BC7 rotation shift overflow (bcpack.rs:866, attempt to shift right with overflow) within a few minutes. It is the bug #3111 fixes; with #3111 applied, the input no longer panics and the target ran 30 min clean (details in #3111).
  • No other crashes in 30 min per target.

Tested

  • WSL2, Ubuntu 26.04.1 LTS on Windows 11, AMD Ryzen 5 5600GT, rustc 1.102.0-nightly (6c709eb42 2026-11-25)
  • cargo test -p victory-formats: 46 passed, 0 failed, 5 ignored
  • cargo +nightly fuzz build --debug-assertions: OK
  • 30 min per target with --debug-assertions:
    • bcpack_decode on main (63bcca4): 14,055,889 execs, no crash
    • bcpack_tables on main + #3111: 1,532,884 execs, no crash
    • xma_frames on main (63bcca4): 3,646,222 execs, no crash (-max_len=16385)

Not tested

  • Building or running the fuzz crate on Windows/MSVC; libFuzzer support there is limited, so Linux/WSL is the documented path.
  • texture.rs has no target yet.
**@⁠gabrielvbraga** on GitHub · 2026-11-26 18:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3324) `gabrielvbraga:fuzz-formats` → `main` · +252 −0 · 7 files · 2 commits · open Closes #3311. Adds a standalone `fuzz/` crate with three cargo-fuzz targets for `victory-formats`: - `bcpack_tables`: `Tables::parse` on raw bytes and on the shipped tables with fuzzer-chosen bytes overwritten, then `decode` with any tables that still parse. - `bcpack_decode`: `decode` for every supported BC format (1, 3, 4, 5, 6, 7) with the shipped tables. - `xma_frames`: `packet`, `read_frame` (packet walk and arbitrary bit offsets) and `Decoder::decode` / `flush`. The crate has its own `[workspace]`, so the main build, tests, CI and `rust-toolchain.toml` are unaffected; nightly is only needed to run it. No game data, corpora or binaries are committed. New dependency: `libfuzzer-sys` (MIT/Apache-2.0, libFuzzer under Apache-2.0 with LLVM exception), used only in this crate. `fuzz/README.md` explains how to run it and turn a crash into a regression test. ## Findings - `bcpack_tables` independently found the BC7 rotation shift overflow (`bcpack.rs:866`, `attempt to shift right with overflow`) within a few minutes. It is the bug #3111 fixes; with #3111 applied, the input no longer panics and the target ran 30 min clean (details in #3111). - No other crashes in 30 min per target. ## Tested - WSL2, Ubuntu 26.04.1 LTS on Windows 11, AMD Ryzen 5 5600GT, `rustc 1.102.0-nightly (6c709eb42 2026-11-25)` - `cargo test -p victory-formats`: 46 passed, 0 failed, 5 ignored - `cargo +nightly fuzz build --debug-assertions`: OK - 30 min per target with `--debug-assertions`: - `bcpack_decode` on `main` (63bcca4): 14,055,889 execs, no crash - `bcpack_tables` on `main` + #3111: 1,532,884 execs, no crash - `xma_frames` on `main` (63bcca4): 3,646,222 execs, no crash (`-max_len=16385`) ## Not tested - Building or running the fuzz crate on Windows/MSVC; libFuzzer support there is limited, so Linux/WSL is the documented path. - `texture.rs` has no target yet.
victory-formats is pure bytes-in/bytes-out, so it can be fuzzed without
game data. The noise_* tests use a fixed xorshift stream; these targets
are coverage-guided and keep overflow checks on.

The fuzz crate has its own workspace, so the main build, tests and CI
never build it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:12:04 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:29 UTC · original

Quick correction to the clippy line above: cargo check --manifest-path fuzz/Cargo.toml --all-targets and cargo xtask policy (198 files ok) both passed, while cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings on Rust 1.98 flagged one minor pedantic/nursery-free lint in fuzz/fuzz_targets/bcpack_tables.rs:16:

  • clippy::chunks_exact_to_as_chunks: data.chunks_exact(4) -> data.as_chunks::<4>().0.

The targets themselves are unaffected (fuzz/ is a separate workspace).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3324#issuecomment-7200522956) Quick correction to the clippy line above: `cargo check --manifest-path fuzz/Cargo.toml --all-targets` and `cargo xtask policy` (198 files ok) both passed, while `cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings` on Rust 1.98 flagged one minor pedantic/nursery-free lint in `fuzz/fuzz_targets/bcpack_tables.rs:16`: - `clippy::chunks_exact_to_as_chunks`: `data.chunks_exact(4)` -> `data.as_chunks::<4>().0`. The targets themselves are unaffected (`fuzz/` is a separate workspace). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:29 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Isolated [workspace] in fuzz/Cargo.toml keeps the main workspace/CI unaffected while adding clean, bounded cargo-fuzz targets for bcpack::Tables::parse, bcpack::decode, and xma packet/frame decoding.
  • cargo check --manifest-path fuzz/Cargo.toml --all-targets: clean.
  • cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings: clean.
  • cargo xtask policy: 198 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3324#pullrequestreview-6078991526) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Isolated `[workspace]` in `fuzz/Cargo.toml` keeps the main workspace/CI unaffected while adding clean, bounded `cargo-fuzz` targets for `bcpack::Tables::parse`, `bcpack::decode`, and `xma` packet/frame decoding. - `cargo check --manifest-path fuzz/Cargo.toml --all-targets`: clean. - `cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 198 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠gabrielvbraga on GitHub · 2026-11-26 18:38 UTC · original

Thanks for testing and for the catch. Fixed in the latest commit: bcpack_tables now uses data.as_chunks::<4>().0. cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings is clean on both 1.98.1 and nightly, and cargo +nightly fuzz build --debug-assertions still builds.

**@⁠gabrielvbraga** on GitHub · 2026-11-26 18:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/3324#issuecomment-7200693598) Thanks for testing and for the catch. Fixed in the latest commit: `bcpack_tables` now uses `data.as_chunks::<4>().0`. `cargo clippy --manifest-path fuzz/Cargo.toml --all-targets -- -D warnings` is clean on both 1.98.1 and nightly, and `cargo +nightly fuzz build --debug-assertions` still builds.
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/3324/head:github-bot/gh-3324'
git switch 'github-bot/gh-3324'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3324'
git switch 'github-bot/gh-3324'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3324'
git switch 'github-bot/gh-3324'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3324'
git switch 'main'
git merge --squash 'github-bot/gh-3324'
git switch 'main'
git merge --ff-only 'github-bot/gh-3324'
git switch 'main'
git merge 'github-bot/gh-3324'
git push origin 'main'
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!3324
No description provided.