Grow DirectStorage BCPack intermediates as zlib inflates #1238

Closed
Jitheswar wants to merge 1 commit from upstream-pr/1238 into main
Jitheswar commented 2026-11-24 16:43:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jitheswar on 2026-11-24T16:43:56Z.


BCPack requests with a zlib stage inflate into an intermediate buffer before BCPack decoding. That buffer was allocated at the request's intermediate_size up front, vec![0; intermediate_size], and truncated after inflating. Titles pass a generous limit there, so each such request zero-filled a buffer far larger than its data (64 MiB for a small texture in the test fixture).

What changes: inflate_intermediate uses miniz_oxide's decompress_to_vec_zlib_with_limit. The buffer grows as bytes arrive and never exceeds the limit. Inflate errors map to INVALID_DATA, as before.

Test (synthetic): zlib_intermediate_grows_with_output_and_respects_its_limit:

  • 2 KiB of data inflates identically with a 64 MiB limit, and the buffer's capacity stays below the limit;
  • an exact limit works, and one byte short is refused;
  • a corrupted Adler-32 checksum is still refused with room to spare.

For the BC4 fixture, intermediate capacity drops from 64 MiB to 116 bytes, with identical decoded output. Windows-target clippy and the asset policy pass. victory-hle tests for the Windows target under Proton 11, merged onto 940d32f: 142 passed / 2 failed. Plain 940d32f gives 141 / 2 with the same two Wine-host failures (only_loopback_is_reachable, a_kept_blob_past_the_link_limit_is_copied); this PR adds the test above. Not run in the game for this change. Merges cleanly onto 940d32f.

AI-assisted (Claude Code, Codex).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6586800305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1238). Originally posted by [Jitheswar](https://github.com/Jitheswar) on 2026-11-24T16:43:56Z. --- BCPack requests with a zlib stage inflate into an intermediate buffer before BCPack decoding. That buffer was allocated at the request's `intermediate_size` up front, `vec![0; intermediate_size]`, and truncated after inflating. Titles pass a generous limit there, so each such request zero-filled a buffer far larger than its data (64 MiB for a small texture in the test fixture). **What changes:** `inflate_intermediate` uses `miniz_oxide`'s `decompress_to_vec_zlib_with_limit`. The buffer grows as bytes arrive and never exceeds the limit. Inflate errors map to `INVALID_DATA`, as before. **Test (synthetic):** `zlib_intermediate_grows_with_output_and_respects_its_limit`: - 2 KiB of data inflates identically with a 64 MiB limit, and the buffer's capacity stays below the limit; - an exact limit works, and one byte short is refused; - a corrupted Adler-32 checksum is still refused with room to spare. For the BC4 fixture, intermediate capacity drops from 64 MiB to 116 bytes, with identical decoded output. Windows-target clippy and the asset policy pass. `victory-hle` tests for the Windows target under Proton 11, merged onto `940d32f`: 142 passed / 2 failed. Plain `940d32f` gives 141 / 2 with the same two Wine-host failures (`only_loopback_is_reachable`, `a_kept_blob_past_the_link_limit_is_copied`); this PR adds the test above. Not run in the game for this change. Merges cleanly onto `940d32f`. AI-assisted (Claude Code, Codex). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Zipettte commented 2026-11-24 18:06:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:35Z.


Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 591932a: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140000135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1238#issuecomment-7140000135). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T17:59:35Z. --- Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 591932a: `cargo test -p victory-hle` passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Marvisak commented 2026-11-25 02:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:27:02Z.


Automated triage for the maintainers.

Needs work. In execute (crates/victory-hle/src/modules/dstorage.rs), the zlib-then-BCPack path now inflates with decompress_to_vec_zlib_with_limit instead of zeroing a buffer of intermediate_size up front. The change is correct: the limit is still enforced, the Adler-32 checksum is still checked, and the error mapping is unchanged. zlib_intermediate_grows_with_output_and_respects_its_limit covers all three.

The benefit isn't shown for the title, though. The "64 MiB → 116 bytes" figure comes from a synthetic test limit. If the title's requests give an intermediate_size close to the inflated size, as the existing inflate comment suggests its chunks do, this only adds reallocations and copies as the vector grows. Please show the gap between intermediate_size and the inflated size on real requests (the existing dstorage trace logs intermediate_size), or a measurement where the up-front allocation costs something.

CI: not run.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149559083 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1238#issuecomment-7149559083). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:27:02Z. --- <!-- victory-triage v1 head=591932ac8ce4645e42d702bf72f0d96b298987bf verdict=needs-work at=2026-11-25T01:27:00Z --> Automated triage for the maintainers. **Needs work.** In `execute` (`crates/victory-hle/src/modules/dstorage.rs`), the zlib-then-BCPack path now inflates with `decompress_to_vec_zlib_with_limit` instead of zeroing a buffer of `intermediate_size` up front. The change is correct: the limit is still enforced, the Adler-32 checksum is still checked, and the error mapping is unchanged. `zlib_intermediate_grows_with_output_and_respects_its_limit` covers all three. The benefit isn't shown for the title, though. The "64 MiB → 116 bytes" figure comes from a synthetic test limit. If the title's requests give an `intermediate_size` close to the inflated size, as the existing `inflate` comment suggests its chunks do, this only adds reallocations and copies as the vector grows. Please show the gap between `intermediate_size` and the inflated size on real requests (the existing `dstorage` trace logs `intermediate_size`), or a measurement where the up-front allocation costs something. CI: not run. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 03:01:59 +00:00
Jitheswar commented 2026-11-25 03:03:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jitheswar on 2026-11-25T02:38:05Z.


Measured as requested, and the review was right. I logged intermediate_size against the inflated length on every zlib-then-BCPack request, local probe only, Grand Theft Auto VI Xbox Series 1.0.2.1 (my own dump), RTX 3050 6 GB under Proton. Two runs, through boot, the menus and about two minutes into the story load and world streaming: zero such requests. On what this title does early on, the path never runs, so there's no measured benefit to set against the extra reallocations you pointed out. Closing; I'll reopen with numbers if a later phase turns out to use it. Thanks for the careful review. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150978521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1238#issuecomment-7150978521). Originally posted by [Jitheswar](https://github.com/Jitheswar) on 2026-11-25T02:38:05Z. --- Measured as requested, and the review was right. I logged `intermediate_size` against the inflated length on every zlib-then-BCPack request, local probe only, Grand Theft Auto VI Xbox Series 1.0.2.1 (my own dump), RTX 3050 6 GB under Proton. Two runs, through boot, the menus and about two minutes into the story load and world streaming: **zero such requests**. On what this title does early on, the path never runs, so there's no measured benefit to set against the extra reallocations you pointed out. Closing; I'll reopen with numbers if a later phase turns out to use it. Thanks for the careful review. AI-assisted (Claude Code).

Pull request closed

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!1238
No description provided.