Game: truncate oversized inflated stream to pack size in shaderpack::find #2794
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2794
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@GuckstduWeitaaa on GitHub · 2026-11-25 20:45 UTC · original
GuckstduWeitaaa:fix/shaderpack-find-truncate→main· +20 −1 · 1 files · 1 commits · openProblem
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.
@fuzeofficlal on GitHub · 2026-11-25 21:10 UTC · original
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.@Marvisak on GitHub · 2026-11-25 23:22 UTC · original
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
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.