Shaders: bound a signature part's register rows and its allocation #1823

Open
github-bot wants to merge 2 commits from github-bot/gh-1823 into main AGit
Owner

@⁠slatefield on GitHub · 2026-11-24 23:02 UTC · original
slatefield:shader/signature-part-bounds → main · +43 −1 · 1 files · 2 commits · open

A signature part's element register comes from the part's own bytes and goes through container.rs as r as u8, and the row count is counted in a byte for PSV0, so a register above 254 is truncated silently. That one is a real bound; it is refused now, with u32::MAX (an unallocated row) still accepted.

Second, the element count read from the part no longer sizes a Vec directly: Vec::with_capacity(count.min(part.len() / 32)). No new error comes with it; a count past the part's rows still fails where a row is read, with the existing Malformed("truncated").

Both are in signature() in crates/victory-shader/src/emit/mod.rs, with tests for the register bound and for the truncated read.

Checked here: cargo test -p victory-shader --lib 120 passed, 1 ignored; Windows-target clippy --all-targets --all-features clean. sinan-cmyk ran the program-by-program comparison on the retail pack at main 940d32f: 23,917 validated on both, no failure reason changes, so the bounds reject nothing on real data.

This is the trimmed version: the earlier row-mask check and the up-front count error were removed after triage, as they only mattered for damaged input.

**@⁠slatefield** on GitHub · 2026-11-24 23:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823) `slatefield:shader/signature-part-bounds` → `main` · +43 −1 · 1 files · 2 commits · open A signature part's element register comes from the part's own bytes and goes through `container.rs` as `r as u8`, and the row count is counted in a byte for PSV0, so a register above 254 is truncated silently. That one is a real bound; it is refused now, with `u32::MAX` (an unallocated row) still accepted. Second, the element count read from the part no longer sizes a `Vec` directly: `Vec::with_capacity(count.min(part.len() / 32))`. No new error comes with it; a count past the part's rows still fails where a row is read, with the existing `Malformed("truncated")`. Both are in `signature()` in `crates/victory-shader/src/emit/mod.rs`, with tests for the register bound and for the truncated read. Checked here: `cargo test -p victory-shader --lib` 120 passed, 1 ignored; Windows-target clippy `--all-targets --all-features` clean. sinan-cmyk ran the program-by-program comparison on the retail pack at `main` `940d32f`: 23,917 validated on both, no failure reason changes, so the bounds reject nothing on real data. This is the trimmed version: the earlier row-mask check and the up-front count error were removed after triage, as they only mattered for damaged input.
A signature part's first dword is its element count, and it went into
Vec::with_capacity unchecked: a damaged part asking for 0x3fffffff rows
tried to allocate 51 GB and aborted the process, with no ShaderError and
no cache entry. The rows must lie in the part, 32 bytes each; a row's
mask and register are checked too, as they feed a shift and the PSV0
table.
Trimmed to what the triage asked for. The count from the part no longer
sizes the allocation (it is clamped to the part's length), and the row
mask check is gone: those only matter for damaged input, and the row
reads already fail on truncation. What stays is the one check with a
real basis, PSV0 counts a signature's register rows in a byte, plus the
capacity clamp.

cargo test -p victory-shader --lib 120 passed, 1 ignored; Windows-target
clippy --all-targets --all-features clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:45:44 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 23:06 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#issuecomment-7147027232) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:31 UTC · original · edited 2026-11-25 14:51 UTC

Automated triage for the maintainers.

Merge candidate (small). signature in crates/victory-shader/src/emit/mod.rs now refuses an element whose register is above 254 (an unallocated u32::MAX is still accepted). It also sizes its Vec by count.min(part.len() / 32) instead of the raw count. The register bound has a real basis: container.rs writes the start row as r as u8 and counts the signature's vectors in a byte for PSV0, so a larger register would be truncated silently. The capacity clamp is a one-line change with no new error: a count past the part's bytes still fails on the row read with Malformed("truncated"), as the new test checks.

On your reply: thanks, this is the trimmed version that was asked for. The mask check is gone, and the register bound and its test are kept. The clamp is fine to keep. The PR description still mentions the mask check, so please update it before merge.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#issuecomment-7154881999) · edited 2026-11-25 14:51 UTC <!-- victory-triage v1 head=4fe6dda5f507f66f1221ebc99e1a358f1ce809d1 verdict=merge-candidate at=2026-11-25T14:53:30Z --> Automated triage for the maintainers. **Merge candidate (small).** `signature` in `crates/victory-shader/src/emit/mod.rs` now refuses an element whose register is above 254 (an unallocated `u32::MAX` is still accepted). It also sizes its `Vec` by `count.min(part.len() / 32)` instead of the raw count. The register bound has a real basis: `container.rs` writes the start row as `r as u8` and counts the signature's vectors in a byte for PSV0, so a larger register would be truncated silently. The capacity clamp is a one-line change with no new error: a count past the part's bytes still fails on the row read with `Malformed("truncated")`, as the new test checks. On your reply: thanks, this is the trimmed version that was asked for. The mask check is gone, and the register bound and its test are kept. The clamp is fine to keep. The PR description still mentions the mask check, so please update it before merge. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 12:24 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 60561410 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,917 on main, 23,917 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 12:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#issuecomment-7162341311) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 60561410 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,917 on `main`, 23,917 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠slatefield on GitHub · 2026-11-25 12:59 UTC · original

Trimmed as asked, in 4fe6dda on the branch:

  • The count no longer sizes the allocation: Vec::with_capacity(count.min(part.len() / 32)). No new error for it; a count past the part still fails on the row read with the existing Malformed("truncated").
  • The row-mask check is gone (damaged input only).
  • Kept the register bound, which has the PSV0 basis you named, and the test for it.

cargo test -p victory-shader --lib: 120 passed, 1 ignored. Windows-target clippy --all-targets --all-features: clean. The PR now rejects nothing that main accepts, which matches sinan-cmyk's program-by-program count on the retail dump (23,917 validated on both).

If the capacity clamp alone still feels like it is guarding input the title cannot produce, say so and I will drop it too; the register bound is the only part I would defend as a real fix.

**@⁠slatefield** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#issuecomment-7163140087) Trimmed as asked, in `4fe6dda` on the branch: - The count no longer sizes the allocation: `Vec::with_capacity(count.min(part.len() / 32))`. No new error for it; a count past the part still fails on the row read with the existing `Malformed("truncated")`. - The row-mask check is gone (damaged input only). - Kept the register bound, which has the PSV0 basis you named, and the test for it. `cargo test -p victory-shader --lib`: 120 passed, 1 ignored. Windows-target clippy `--all-targets --all-features`: clean. The PR now rejects nothing that `main` accepts, which matches sinan-cmyk's program-by-program count on the retail dump (23,917 validated on both). If the capacity clamp alone still feels like it is guarding input the title cannot produce, say so and I will drop it too; the register bound is the only part I would defend as a real fix.
Author
Owner

@⁠Melow-code on GitHub · 2026-11-24 23:08 UTC · original · requested changes

The count bound is correct. The mask check has a gap: mask.count_ones() > 4 stops the 1u8 << cols overflow but does not refuse bits above w. A mask like 0x10 or 0xF0 passes:

  • col = trailing_zeros().min(3) clamps the element to w silently.
  • cols can be 4 with col 3, and the rebuilt mask in container.rs becomes 0x78 — outside the four components.

Fix: if mask & 0xF0 != 0 { return Err(...) } before the loop. A test with mask 0x10 would cover it.

**@⁠Melow-code** on GitHub · 2026-11-24 23:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#pullrequestreview-6048849004) · **requested changes** The count bound is correct. The mask check has a gap: `mask.count_ones() > 4` stops the `1u8 << cols` overflow but does not refuse bits above w. A mask like `0x10` or `0xF0` passes: - `col = trailing_zeros().min(3)` clamps the element to w silently. - `cols` can be 4 with `col` 3, and the rebuilt mask in container.rs becomes `0x78` — outside the four components. Fix: `if mask & 0xF0 != 0 { return Err(...) }` before the loop. A test with mask `0x10` would cover it.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 23:52 UTC · original · approved these changes

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 120 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.

Signature part rows bounded by the…: row-bound validation in structure/lower paths.

**@⁠catminou4** on GitHub · 2026-11-24 23:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#pullrequestreview-6049332752) · **approved these changes** Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 120 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows. Signature part rows bounded by the…: row-bound validation in structure/lower paths.
Author
Owner

@⁠Melow-code on GitHub · 2026-11-25 11:54 UTC · original · requested changes

The count bound is correct. count > part.len().saturating_sub(base) / 32 also refuses a base past the end. After the check, base + 32 * i stays in the part.

One gap in the mask check. mask.count_ones() > 4 stops the 1u8 << cols overflow, but it does not refuse bits above w. A damaged mask such as 0x10 or 0xF0 passes:

  • col is trailing_zeros().min(3), so the clamp moves the element to w without an error.
  • cols can be 4 with col 3, and then the rebuilt mask in container.rs is 0x78, which is outside the four components.

if mask & 0xF0 != 0 refuses all of these cases and also prevents the overflow. A test with 0x10 would cover it.

The register bound (at most 254, or u32::MAX for no register) agrees with a PSV0 row count held in a byte.

**@⁠Melow-code** on GitHub · 2026-11-25 11:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#pullrequestreview-6057118421) · **requested changes** The count bound is correct. `count > part.len().saturating_sub(base) / 32` also refuses a `base` past the end. After the check, `base + 32 * i` stays in the part. One gap in the mask check. `mask.count_ones() > 4` stops the `1u8 << cols` overflow, but it does not refuse bits above w. A damaged mask such as `0x10` or `0xF0` passes: - `col` is `trailing_zeros().min(3)`, so the clamp moves the element to w without an error. - `cols` can be 4 with `col` 3, and then the rebuilt mask in `container.rs` is `0x78`, which is outside the four components. `if mask & 0xF0 != 0` refuses all of these cases and also prevents the overflow. A test with `0x10` would cover it. The register bound (at most 254, or `u32::MAX` for no register) agrees with a PSV0 row count held in a byte.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:47 UTC · original · approved these changes

Verified 4fe6dda5f507f66f1221ebc99e1a358f1ce809d1 cleanly merged onto main (63bcca43) on Windows 11 x64:

  • signature (crates/victory-shader/src/emit/mod.rs:548, 620-622) cleanly bounds initial Vec allocation by part.len() / 32 and rejects register > 254 (keeping u32::MAX for unallocated rows) to match PSV0's u8 row-count encoding.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok); cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • cargo test --locked -p victory-shader --lib emit::tests::: 19 passed, 0 failed (a_signature_count_past_its_rows_is_refused and a_signature_register_outside_its_field_is_refused pass).

Minor doc/test notes (non-blocking): worth updating the PR description to drop mention of the removed mask check, and optionally pinning the exact 254/255 register boundary. Ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1823#pullrequestreview-6079150334) · **approved these changes** Verified `4fe6dda5f507f66f1221ebc99e1a358f1ce809d1` cleanly merged onto `main` (`63bcca43`) on Windows 11 x64: - `signature` (`crates/victory-shader/src/emit/mod.rs:548, 620-622`) cleanly bounds initial `Vec` allocation by `part.len() / 32` and rejects `register > 254` (keeping `u32::MAX` for unallocated rows) to match PSV0's `u8` row-count encoding. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`); `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `cargo test --locked -p victory-shader --lib emit::tests::`: `19 passed, 0 failed` (`a_signature_count_past_its_rows_is_refused` and `a_signature_register_outside_its_field_is_refused` pass). Minor doc/test notes (non-blocking): worth updating the PR description to drop mention of the removed mask check, and optionally pinning the exact `254`/`255` register boundary. Ready to merge.
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/1823/head:github-bot/gh-1823'
git switch 'github-bot/gh-1823'

Merge

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