Game: truncate oversized inflated stream to pack size in shaderpack::find #2792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2794"
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 GuckstduWeitaaa on 2026-11-25T20:45:55Z.
Problem
When a game archive stores a shader pack across zlib streams and the final inflated stream decompresses beyond the pack's declared total size (e.g. contains trailing bytes or padding from adjacent archive entries in container chunks),
pack.len() >= totalevaluates totrue, but the previous strict equality check(pack.len() == total).then_some(...)evaluates toNone. As a result, valid shader packs with trailing stream data were discarded andshaderpack::findreturnedNone.Fix
Truncate
packtototalso valid shader packs inflate cleanly and are returned asSome(std::borrow::Cow::Owned(pack))wheneverpack.len() >= total.Testing
finds_a_pack_with_trailing_bytes_in_final_zlib_streamincrates/victory-game/src/shaderpack.rs.main(13f91ca), the test fails deterministically withleft: None, right: Some(...). With this fix, the test passes.cargo test -p victory-game --locked.cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features.cargo xtask policy(asset policy: ok).cargo test --workspace --locked.Coordination: claimed on #1633 (comment 7173955918).
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T21:12:08Z.
Review: COMMENTED
Verified on Linux (Rust 1.99.0)
Branch: current
main(13f91ca) + this PR (fast-forward, no conflicts with main).cargo test --locked -p victory-game: 16 passed.finds_a_pack_with_trailing_bytes_in_final_zlib_streamfails withleft: None, right: Some(..), so the test does pin the change.cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-game --all-targets -- -D warnings: clean, same as main.Findings
Conflicts with #2534, which relies on the check this PR removes. #2534 (open, mergeable, same function) changes
findto scan past false-positiveMAGICstreams. It relies on thepack.len() == totalcheck that this PR removes: on a mismatch itbreaks and tries the next candidate.git merge pr-2534 pr-2794conflicts incrates/victory-game/src/shaderpack.rs. Whichever lands second has to decide how "trailing bytes" and "wrong candidate" are told apart. Without the strict equality, every overshoot is accepted.The equality was the only consistency check in
find, and a wrongSomestops the caller's search.apps/victory/src/prebuild.rs:57does.find_map(|(p, d)| Some((p, shaderpack::find(d)?)))across every candidate file. On main, a stream that starts withPS\0\x09but whose header gives a size smaller than its output returnsNone, and prebuild moves on to the next file. With this change it returnsSome(truncated).Pack::parse(prebuild.rs:62,?) would then most likely reject it with "... refers outside the tables", and prebuild errors out instead of trying the next file. That needs a falseMAGIC, so it is unlikely, but it is the case the old check covered.Suggestion: when
pack.len() > total, accept the truncated pack only ifPack::parse(&pack[..total])succeeds, and otherwise keep returningNone. That keeps the fix for trailing data and still turns away a wrong candidate. It also fits #2534's loop:breakon a pack that fails to parse.Not verified
Noneand this PR returns the pack would make the case.Reviewed with Claude Code.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:13:36Z.
Review: COMMENTED
Verified:
size(&pack)is the pack's own declared total, andpack.len() >= talready guarantees no under-read — truncating the over-inflated tail is the right fix for archives whose final zlib stream runs into a trailing entry's bytes. The old== totalgate would reject a real archive. Test constructs exactly that layout (split pack + trailing data in the second stream). LGTM.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:10:51Z.
Reviewed and verified
07b32970on Windows 11 againstmain(13f91ca).total(pack.truncate(total)) whenpack.len() >= totalsafely handles trailing bytes after the final zlib stream without expanding allocation, whileinflate's fixed 128 KiB buffer +TINFLStatus::Donecheck andShaderPack::parsebounds checks keep malformed/oversized inputs bounded.cargo test --locked -p victory-game: 16 passed, 0 failed (includingfinds_a_pack_with_trailing_bytes_in_final_zlib_stream).cargo clippy --locked -p victory-game --all-targets -- -D warnings: 0 warnings;cargo xtask policy: 184 files ok; cleangit merge-treevs13f91ca.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:22:20Z.
Automated triage for the maintainers.
In
crates/victory-game/src/shaderpack.rs,findpreviously returnedNoneunless the inflated streams added up to exactly the size the pack header gives. This PR truncates any excess instead. That strict equality also served as the check that the size formula insizeis right and that the run of streams is really the pack. With truncation, a wrong size or a stray extra stream would silently produce a cut-off pack instead ofNone.The case the PR handles (a final zlib stream carrying bytes after the pack) is built only in a synthetic test. Nothing shows that an archive of the title is laid out this way. What would change the verdict: evidence that a real archive hits this, e.g. which archive or file layout and the observed sizes, described without including any game data. Alternatively, a narrower rule such as accepting excess only in the last stream and only below 16 bytes of padding, if that is what the format does.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T23:55:25Z.
Independent Windows verification of PR #2794 (Game: truncate oversized inflated stream to pack size in
shaderpack::find).07b3297, merge-base13f91ca. OPEN, MERGEABLE/CLEAN, non-draft, no formal approval, no prior comment from me.cargo test --locked, worktree-localCARGO_TARGET_DIR,CARGO_BUILD_JOBS=2(repo pins 1.98.1; no clippy/rustup). No game data, synthetic zlib fixture only, GPU/driver N/A.cargo test --locked -p victory-game finds_a_pack_with_trailing_bytes_in_final_zlib_streamtest result: ok. 1 passed; 0 failed; 0 ignored; 15 filtered out(shaderpack::tests::finds_a_pack_with_trailing_bytes_in_final_zlib_stream).git diff --checkagainst merge-base13f91ca: clean (exit 0).origin/main(0 hits).Caveat: I focused on the targeted synthetic test; I did not run the full crate suite or test with a real game shader pack.
AI-assisted (Hy4 flash). No game assets, extracted shaders, keys or DRM content used or uploaded.
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.