Shaders: bound the bytes one part's native blobs unpack to and hand out #1620

Open
imjustprism wants to merge 1 commit from upstream-pr/1621 into main
imjustprism commented 2026-11-24 19:52:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-24T19:52:31Z.


a dxil part's xdat index can name the same native blob up to 64 times, and a blob's 8 stage slots can all point at one code range. each blob was only capped at 16 MiB unpacked on its own, so a container of a few KB could make native_programs inflate 1 GiB and copy out about 8 GiB of code before translation even starts. the bytes a part's blobs unpack to and the code and raw table bytes read out of them now come off one 16 MiB budget, and running out is refused as malformed.

real blobs are a few KiB. on a retail dump all 26,148 native programs still read and none hits the new refusal (that run was on an earlier revision of this branch with the same limits). four synthetic tests, each fails without its part of the change. clippy both ways, cargo test --workspace (346 passed) and xtask policy on windows 11.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590140317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-24T19:52:31Z. --- a dxil part's xdat index can name the same native blob up to 64 times, and a blob's 8 stage slots can all point at one code range. each blob was only capped at 16 MiB unpacked on its own, so a container of a few KB could make native_programs inflate 1 GiB and copy out about 8 GiB of code before translation even starts. the bytes a part's blobs unpack to and the code and raw table bytes read out of them now come off one 16 MiB budget, and running out is refused as malformed. real blobs are a few KiB. on a retail dump all 26,148 native programs still read and none hits the new refusal (that run was on an earlier revision of this branch with the same limits). four synthetic tests, each fails without its part of the change. clippy both ways, cargo test --workspace (346 passed) and xtask policy on windows 11.
DenRakEiw commented 2026-11-24 20:02:56 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib native:: — 14 passed, 0 failed (including the 4 new PartBudget size-budget tests)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean PartBudget accounting for unpacked native blobs, code, and root tables so oversized blobs are rejected before inflating. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046365542 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#pullrequestreview-6046365542). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T19:56:43Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib native::` — 14 passed, 0 failed (including the 4 new `PartBudget` size-budget tests) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean `PartBudget` accounting for unpacked native blobs, code, and root tables so oversized blobs are rejected before inflating. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-24 21:02:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:05:29Z.

Review: APPROVED


Native blob unpacking is now bounded by a PartBudget: code, root tables and unpacked blob bytes all come off one budget, and an oversized blob is refused before it inflates (zip-bomb protection for malformed SGDs). Four new tests cover each budget site and the early refusal. macOS arm64: cargo test -p victory-shader --locked → 100 passed, 0 failed (+4).

<!-- greyfinch-sync:Marvisak/VIctory:review:6046495914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#pullrequestreview-6046495914). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:05:29Z. **Review:** APPROVED --- Native blob unpacking is now bounded by a `PartBudget`: code, root tables and unpacked blob bytes all come off one budget, and an oversized blob is refused before it inflates (zip-bomb protection for malformed SGDs). Four new tests cover each budget site and the early refusal. macOS arm64: `cargo test -p victory-shader --locked` → **100 passed, 0 failed (+4)**.
Marvisak commented 2026-11-25 04:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:31:42Z.


Automated triage for the maintainers.

Merge candidate. This replaces the per-blob MAX_UNPACKED cap in native.rs with one 16 MiB PartBudget per part, covering the unpacked sizes and the code and root-table bytes copied out. That closes the case where one XDAT index names the same blob many times, or a blob's stages share one range. The size is checked before inflating, the usize conversion saturates, and the four tests each cover one path. The author reports that every retail program still reads. CI passes.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151998073 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#issuecomment-7151998073). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:31:42Z. --- <!-- victory-triage v1 head=46b2086986d038b91abe5459a7ad1ef1cf5227c9 verdict=merge-candidate at=2026-11-25T03:33:00Z --> Automated triage for the maintainers. **Merge candidate.** This replaces the per-blob `MAX_UNPACKED` cap in `native.rs` with one 16 MiB `PartBudget` per part, covering the unpacked sizes and the code and root-table bytes copied out. That closes the case where one XDAT index names the same blob many times, or a blob's stages share one range. The size is checked before inflating, the `usize` conversion saturates, and the four tests each cover one path. The author reports that every retail program still reads. CI passes. --- _Generated by [Claude Code](https://claude.ai/code)_
StExpeditus commented 2026-11-25 10:07:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by StExpeditus on 2026-11-25T09:27:51Z.


Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24. Branch at 46b2086. cargo test --workspace --locked --no-fail-fast -> 697 passed, 5 failed, 10 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158364960 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#issuecomment-7158364960). Originally posted by [StExpeditus](https://github.com/StExpeditus) on 2026-11-25T09:27:51Z. --- **Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24.** Branch at `46b2086`. `cargo test --workspace --locked --no-fail-fast` -> 697 passed, 5 failed, 10 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.
fuzeofficlal commented 2026-11-26 01:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:55:28Z.


Code review and Windows 11 verification at head 46b2086986d0 merged cleanly onto main (63bcca43c6a0):

  • Budget & overflow audit (crates/victory-shader/src/native.rs:486-500, 586-648):
    • PartBudget(MAX_PART_BYTES = 16 MiB) debits with checked_sub across the entire part loop (0..count), charging both declared unpacked size (via usize::try_from(...).unwrap_or(usize::MAX) before decompress_to_vec_zlib_with_limit allocates) and extracted code.len() + layout.len() + used.len() (bounded well below overflow since each blob is <= 16 MiB). This prevents both multi-entry zlib inflation and overlapping multi-stage slice amplification from the same blob while returning a clear Malformed error.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-shader -p victory-pipeline --all-targets -- -D warnings: 0 warnings
    • victory-shader --lib -- native::: 17/17 passed (including all 4 new budget tests)
    • victory-pipeline --all-targets: 8/8 passed.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179250143 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#issuecomment-7179250143). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:55:28Z. --- Code review and Windows 11 verification at head `46b2086986d0` merged cleanly onto `main` (`63bcca43c6a0`): - **Budget & overflow audit (`crates/victory-shader/src/native.rs:486-500, 586-648`)**: - `PartBudget(MAX_PART_BYTES = 16 MiB)` debits with `checked_sub` across the entire part loop (`0..count`), charging both declared `unpacked` size (via `usize::try_from(...).unwrap_or(usize::MAX)` *before* `decompress_to_vec_zlib_with_limit` allocates) and extracted `code.len() + layout.len() + used.len()` (bounded well below overflow since each blob is `<= 16 MiB`). This prevents both multi-entry zlib inflation and overlapping multi-stage slice amplification from the same blob while returning a clear `Malformed` error. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy -p victory-shader -p victory-pipeline --all-targets -- -D warnings`: 0 warnings - `victory-shader --lib -- native::`: **17/17 passed** (including all 4 new budget tests) - `victory-pipeline --all-targets`: **8/8 passed**. LGTM.
upstream-sync changed title from [PR #1621] bound the bytes one part's native blobs unpack to and hand out to [PR #1621] Shaders: bound the bytes one part's native blobs unpack to and hand out 2026-11-26 09:05:07 +00:00
fuzeofficlal commented 2026-11-26 13:03:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T12:26:18Z.

Review: APPROVED


Reviewed and verified 46b20869 against origin/main (63bcca43; clean git merge-tree):

  • PartBudget(16 << 20) (crates/victory-shader/src/native.rs:143-152, 454, 595-596, 645-647) checks saturated unpacked sizes (usize::try_from(...).unwrap_or(usize::MAX)) with checked_sub before inflating and charges code.len() + layout.len() + used.len() before copying/collecting, preventing repeated XDAT entries and shared stage ranges from amplifying allocations.

Non-blocking boundary note: because decompression (S) and emitted code/table bytes (P) now share one 16 MiB budget, a single valid code-heavy blob just above ~8 MiB (S + P > 16 MiB) that previously passed MAX_UNPACKED = 16 MiB will now be refused. Documenting that single-blob boundary (or adding exact 16 MiB / 16 MiB + 1 B boundary tests) would lock the contract down cleanly.

Local verification on 46b20869: rustfmt --edition 2024 --check crates/victory-shader/src/native.rs, xtask policy (182 files ok), cargo clippy -p victory-shader --all-targets -- -D warnings (default & --all-features), and cargo test -p victory-shader --lib native:: (17 passed; 0 failed) all pass.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074097740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1621#pullrequestreview-6074097740). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T12:26:18Z. **Review:** APPROVED --- Reviewed and verified `46b20869` against `origin/main` (`63bcca43`; clean `git merge-tree`): - `PartBudget(16 << 20)` (`crates/victory-shader/src/native.rs:143-152, 454, 595-596, 645-647`) checks saturated `unpacked` sizes (`usize::try_from(...).unwrap_or(usize::MAX)`) with `checked_sub` before inflating and charges `code.len() + layout.len() + used.len()` before copying/collecting, preventing repeated XDAT entries and shared stage ranges from amplifying allocations. Non-blocking boundary note: because decompression (`S`) and emitted code/table bytes (`P`) now share one 16 MiB budget, a single valid code-heavy blob just above ~8 MiB (`S + P > 16 MiB`) that previously passed `MAX_UNPACKED = 16 MiB` will now be refused. Documenting that single-blob boundary (or adding exact `16 MiB` / `16 MiB + 1 B` boundary tests) would lock the contract down cleanly. Local verification on `46b20869`: `rustfmt --edition 2024 --check crates/victory-shader/src/native.rs`, `xtask policy` (`182 files ok`), `cargo clippy -p victory-shader --all-targets -- -D warnings` (default & `--all-features`), and `cargo test -p victory-shader --lib native::` (`17 passed; 0 failed`) all pass.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1621:upstream-pr/1621'
git switch 'upstream-pr/1621'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1621'
git switch 'upstream-pr/1621'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1621'
git switch 'upstream-pr/1621'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1621'
git switch 'main'
git merge --squash 'upstream-pr/1621'
git switch 'main'
git merge --ff-only 'upstream-pr/1621'
git switch 'main'
git merge 'upstream-pr/1621'
git push origin 'main'
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!1620
No description provided.