Game: validate DXBC containers in SGD5 records #425
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/425"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
Nonefor 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
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.rsandgit diff --check: clean.cargo xtask policy: 151 files ok. No game files or data taken from them were added.cargo test -p victory-loader --test load_probe. Its fixture passes MSVC's/DELAYLOADflag, which MinGW rejects here; the same failure occurs on unmodifiedmain.Checklist
cargo fmt,cargo clippy --workspace --all-targetsandcargo test --workspacepass — see the toolchain limitations above; the changed crate is clean.cargo xtask policypasses. The change adds no game files or data taken from them (docs/asset-policy.md).Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T05:53:01Z.
Review: APPROVED
Tested
012ce71on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (266 passed, 0 failed).container()checks: the magic,len >= 0x20,0x20 <= total <= len, and thatpartsoffsets fit intotal - 0x20. That rules out the out-of-range slicing a caller could otherwise hit when reading the part table. All ofu32_at's reads are inside the 0x20 bytes already checked, so the?s cannot fail there.total. The description is accurate on this. A caller that walks the parts still needs to check each one.unpack()is untouched.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:38:46Z.
Verified
012ce71on 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).
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) anddigest()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 mainffe310e) → 4 passed / 0 failed.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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.