Game: truncate oversized inflated stream to pack size in shaderpack::find #2794

Open
github-bot wants to merge 1 commit from github-bot/gh-2794 into main AGit
Owner

@⁠GuckstduWeitaaa on GitHub · 2026-11-25 20:45 UTC · original
GuckstduWeitaaa:fix/shaderpack-find-truncate → main · +20 −1 · 1 files · 1 commits · open

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() >= total evaluates to true, but the previous strict equality check (pack.len() == total).then_some(...) evaluates to None. As a result, valid shader packs with trailing stream data were discarded and shaderpack::find returned None.

Fix

Truncate pack to total so valid shader packs inflate cleanly and are returned as Some(std::borrow::Cow::Owned(pack)) whenever pack.len() >= total.

Testing

  • Added synthetic regression test finds_a_pack_with_trailing_bytes_in_final_zlib_stream in crates/victory-game/src/shaderpack.rs.
  • Negative control verification: On unpatched main (13f91ca), the test fails deterministically with left: None, right: Some(...). With this fix, the test passes.
  • Verified cargo test -p victory-game --locked.
  • Verified cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features.
  • Verified cargo xtask policy (asset policy: ok).
  • Verified cargo test --workspace --locked.

Coordination: claimed on #1633 (comment 7173955918).
AI-assisted.

**@⁠GuckstduWeitaaa** on GitHub · 2026-11-25 20:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2794) `GuckstduWeitaaa:fix/shaderpack-find-truncate` → `main` · +20 −1 · 1 files · 1 commits · open ### 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() >= total` evaluates to `true`, but the previous strict equality check `(pack.len() == total).then_some(...)` evaluates to `None`. As a result, valid shader packs with trailing stream data were discarded and `shaderpack::find` returned `None`. ### Fix Truncate `pack` to `total` so valid shader packs inflate cleanly and are returned as `Some(std::borrow::Cow::Owned(pack))` whenever `pack.len() >= total`. ### Testing - Added synthetic regression test `finds_a_pack_with_trailing_bytes_in_final_zlib_stream` in `crates/victory-game/src/shaderpack.rs`. - **Negative control verification:** On unpatched `main` (`13f91ca`), the test fails deterministically with `left: None, right: Some(...)`. With this fix, the test passes. - Verified `cargo test -p victory-game --locked`. - Verified `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`. - Verified `cargo xtask policy` (asset policy: ok). - Verified `cargo test --workspace --locked`. Coordination: claimed on #1633 (comment 7173955918). AI-assisted.
When an 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
records), pack.len() >= total evaluates to true, but the previous
equality check (pack.len() == total).then_some(...) evaluated to None.
Consequently, valid shader packs with trailing stream data were
discarded.

Truncate pack to total so valid shader packs inflate cleanly and are
returned as Some(Cow::Owned(pack)). Adds a synthetic regression test.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:24 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:10 UTC · original

Reviewed and verified 07b32970 on Windows 11 against main (13f91ca).

  • Truncating the inflated stream to total (pack.truncate(total)) when pack.len() >= total safely handles trailing bytes after the final zlib stream without expanding allocation, while inflate's fixed 128 KiB buffer + TINFLStatus::Done check and ShaderPack::parse bounds checks keep malformed/oversized inputs bounded.
  • cargo test --locked -p victory-game: 16 passed, 0 failed (including finds_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; clean git merge-tree vs 13f91ca.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2794#issuecomment-7174719478) Reviewed and verified `07b32970` on Windows 11 against `main` (`13f91ca`). - Truncating the inflated stream to `total` (`pack.truncate(total)`) when `pack.len() >= total` safely handles trailing bytes after the final zlib stream without expanding allocation, while `inflate`'s fixed 128 KiB buffer + `TINFLStatus::Done` check and `ShaderPack::parse` bounds checks keep malformed/oversized inputs bounded. - `cargo test --locked -p victory-game`: **16 passed, 0 failed** (including `finds_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**; clean `git merge-tree` vs `13f91ca`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:22 UTC · original

Automated triage for the maintainers.

In crates/victory-game/src/shaderpack.rs, find previously returned None unless 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 in size is 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 of None.

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2794#issuecomment-7177469648) <!-- victory-triage v1 head=07b329703c580ce3301843741999d7ca28ca8da7 verdict=needs-work at=2026-11-25T23:22:11Z --> Automated triage for the maintainers. In `crates/victory-game/src/shaderpack.rs`, `find` previously returned `None` unless 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 in `size` is 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 of `None`. 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](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2794/head:github-bot/gh-2794'
git switch 'github-bot/gh-2794'

Merge

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