Game: validate DXBC containers in SGD5 records #425

Open
enzoduarte1 wants to merge 1 commit from upstream-pr/425 into main
enzoduarte1 commented 2026-11-24 03:14:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by enzoduarte1 on 2026-11-24T03:14:24Z.


What

Record::unpack() in the SGD5 reader only checks that the deflate stream inflates to the declared length. A record can hold arbitrary bytes, so callers that need a shader container each have to repeat the DXBC header checks (or skip the record later, after counting it).

This adds two accessors to victory-game::sgd5::Record:

  • container(): unpacks and returns the bytes only when they have a DXBC header whose total size and part-offset table fit inside the data;
  • digest(): the 16-byte container digest from that header, for identifying a shader without unpacking again.

Both return None for corrupt streams, non-DXBC payloads and malformed headers. unpack() keeps its existing behavior. Tests use synthetic buffers only: a valid two-part container, a non-shader payload, bad magic, out-of-range total size, part count overflow and a truncated header. No title data is involved.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-game: 4 passed.
  • cargo test --workspace --exclude victory-loader -- --test-threads=1: all suites passed.
  • cargo clippy -p victory-game --all-targets -- -D warnings: clean.
  • rustfmt --edition 2024 --check crates/victory-game/src/sgd5.rs and git diff --check: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's /DELAYLOAD flag, which MinGW rejects here; the same failure occurs on unmodified main.

Checklist

  • cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace pass — see the toolchain limitations above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and tests; I reviewed and ran them.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573796187 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/425). Originally posted by [enzoduarte1](https://github.com/enzoduarte1) on 2026-11-24T03:14:24Z. --- ## What `Record::unpack()` in the SGD5 reader only checks that the deflate stream inflates to the declared length. A record can hold arbitrary bytes, so callers that need a shader container each have to repeat the DXBC header checks (or skip the record later, after counting it). This adds two accessors to `victory-game::sgd5::Record`: - `container()`: unpacks and returns the bytes only when they have a DXBC header whose total size and part-offset table fit inside the data; - `digest()`: the 16-byte container digest from that header, for identifying a shader without unpacking again. Both return `None` for corrupt streams, non-DXBC payloads and malformed headers. `unpack()` keeps its existing behavior. Tests use synthetic buffers only: a valid two-part container, a non-shader payload, bad magic, out-of-range total size, part count overflow and a truncated header. No title data is involved. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-game`: 4 passed. - `cargo test --workspace --exclude victory-loader -- --test-threads=1`: all suites passed. - `cargo clippy -p victory-game --all-targets -- -D warnings`: clean. - `rustfmt --edition 2024 --check crates/victory-game/src/sgd5.rs` and `git diff --check`: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`. Its fixture passes MSVC's `/DELAYLOAD` flag, which MinGW rejects here; the same failure occurs on unmodified `main`. ## Checklist - [ ] `cargo fmt`, `cargo clippy --workspace --all-targets` and `cargo test --workspace` pass — see the toolchain limitations above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and tests; I reviewed and ran them.
mercuryVM commented 2026-11-24 06:52:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:53:01Z.

Review: APPROVED


Tested 012ce71 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (266 passed, 0 failed).

  • container() checks: the magic, len >= 0x20, 0x20 <= total <= len, and that parts offsets fit in total - 0x20. That rules out the out-of-range slicing a caller could otherwise hit when reading the part table. All of u32_at's reads are inside the 0x20 bytes already checked, so the ?s cannot fail there.
  • Scope note: it validates that the part-offset table fits, not that each part offset (or part header) lies inside total. The description is accurate on this. A caller that walks the parts still needs to check each one.
  • Nothing calls the two accessors yet, so this is API only, with no behaviour change. unpack() is untouched.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034352770 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/425#pullrequestreview-6034352770). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T05:53:01Z. **Review:** APPROVED --- Tested 012ce71 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (266 passed, 0 failed). - `container()` checks: the magic, `len >= 0x20`, `0x20 <= total <= len`, and that `parts` offsets fit in `total - 0x20`. That rules out the out-of-range slicing a caller could otherwise hit when reading the part table. All of `u32_at`'s reads are inside the 0x20 bytes already checked, so the `?`s cannot fail there. - Scope note: it validates that the part-offset *table* fits, not that each part offset (or part header) lies inside `total`. The description is accurate on this. A caller that walks the parts still needs to check each one. - Nothing calls the two accessors yet, so this is API only, with no behaviour change. `unpack()` is untouched. AI-assisted (Claude Code).
DaviTostes commented 2026-11-24 06:55:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:38:46Z.


Verified 012ce71 on Arch Linux x86_64 (rustc 1.98.1, cargo test -p victory-game): 4 passed, 0 failed, 0 ignored.

Not covered: SGD5 streams from the title's archives (no game data here).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121289343 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/425#issuecomment-7121289343). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T03:38:46Z. --- Verified `012ce71` on **Arch Linux x86_64** (rustc 1.98.1, `cargo test -p victory-game`): **4 passed, 0 failed, 0 ignored**. Not covered: SGD5 streams from the title's archives (no game data here).
catminou4 commented 2026-11-24 14:03:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:20:38Z.

Review: APPROVED


Record::container() validates the unpacked bytes as a DXBC container (magic, 0x20 header, total size ≤ buffer, part count within bounds) and digest() exposes the 16-byte container digest for cache keys — exactly what shader-cache callers need without double-unpacking. The header layout (magic 4 + digest 16 + version 4 + length 4 + parts 4 = 0x20) is correct.

Tests are thorough and asset-policy clean (synthetic digest, comment says so): valid container round-trip, non-container payload still unpacks but isn't a container, four malformed-header variants, truncated header. cargo test -p victory-game --locked (macOS arm64, rustc 1.98.1, merged with main ffe310e) → 4 passed / 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039913538 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/425#pullrequestreview-6039913538). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T13:20:38Z. **Review:** APPROVED --- `Record::container()` validates the unpacked bytes as a DXBC container (magic, 0x20 header, total size ≤ buffer, part count within bounds) and `digest()` exposes the 16-byte container digest for cache keys — exactly what shader-cache callers need without double-unpacking. The header layout (magic 4 + digest 16 + version 4 + length 4 + parts 4 = 0x20) is correct. Tests are thorough and asset-policy clean (synthetic digest, comment says so): valid container round-trip, non-container payload still unpacks but isn't a container, four malformed-header variants, truncated header. `cargo test -p victory-game --locked` (macOS arm64, rustc 1.98.1, merged with main `ffe310e`) → **4 passed / 0 failed**.
Marvisak commented 2026-11-25 01:07:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:17:06Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-game/src/sgd5.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148348134 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/425#issuecomment-7148348134). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:17:06Z. --- <!-- victory-triage v1 head=012ce71c5a8ce7ed19c9d443a691136924e6ebdc verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-game/src/sgd5.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/425:upstream-pr/425'
git switch 'upstream-pr/425'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/425'
git switch 'upstream-pr/425'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/425'
git switch 'upstream-pr/425'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/425'
git switch 'main'
git merge --squash 'upstream-pr/425'
git switch 'main'
git merge --ff-only 'upstream-pr/425'
git switch 'main'
git merge 'upstream-pr/425'
git push origin 'main'
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!425
No description provided.