Shaders: guard VsInput VGPR and PS root SGPR additions against overflow in io::raise #3076

Closed
github-bot wants to merge 1 commit from github-bot/gh-3076 into main AGit
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 06:42 UTC · original
Dukestar69:fix/io-raise-checked-registers → main · +43 −2 · 1 files · 1 commits · closed without merging

Summary

Guards two unchecked register-index additions in io::raise (crates/victory-shader/src/io.rs) against integer overflow on malformed or boundary FSSM shader metadata:

  1. StageIo::Vs (i.vgpr + channel): uses checked_add(channel) and returns ShaderError::Malformed("vertex input VGPR out of bounds") instead of panicking in debug builds or wrapping onto v0..=v2 (VertexId/PrimitiveId) in release builds when vgpr >= 253 and mask sets an overflowing channel.
  2. StageIo::Ps (u32::from(r.user_data) + r.sgprs): uses saturating_add(r.sgprs) so large sgprs counts in root parameters cannot overflow u32 (or wrap below the .clamp(8, 104) upper bound in release builds).

Verification

  • Added unit test io::tests::raise_handles_extreme_vs_vgpr_and_ps_root_sgprs_without_overflow:
    • Failed on 63bcca4 (panicked at crates/victory-shader/src/io.rs:239:41: attempt to add with overflow).
    • Passes with fix.
  • cargo test -p victory-shader io::tests: 5 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 06:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3076) `Dukestar69:fix/io-raise-checked-registers` → `main` · +43 −2 · 1 files · 1 commits · closed without merging ## Summary Guards two unchecked register-index additions in `io::raise` (`crates/victory-shader/src/io.rs`) against integer overflow on malformed or boundary FSSM shader metadata: 1. `StageIo::Vs` (`i.vgpr + channel`): uses `checked_add(channel)` and returns `ShaderError::Malformed("vertex input VGPR out of bounds")` instead of panicking in debug builds or wrapping onto `v0..=v2` (`VertexId`/`PrimitiveId`) in release builds when `vgpr >= 253` and `mask` sets an overflowing channel. 2. `StageIo::Ps` (`u32::from(r.user_data) + r.sgprs`): uses `saturating_add(r.sgprs)` so large `sgprs` counts in root parameters cannot overflow `u32` (or wrap below the `.clamp(8, 104)` upper bound in release builds). ### Verification - Added unit test `io::tests::raise_handles_extreme_vs_vgpr_and_ps_root_sgprs_without_overflow`: - Failed on `63bcca4` (`panicked at crates/victory-shader/src/io.rs:239:41: attempt to add with overflow`). - Passes with fix. - `cargo test -p victory-shader io::tests`: 5 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:54:55 +00:00
Author
Owner

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

Tested locally on Windows 11 x64 (rustc 1.98.1):

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.
  • cargo test -p victory-shader --locked io::tests: 5 passed, 0 failed.

The VS checked_add cleanly rejects u8 register-number overflow while preserving v255 as a valid single-channel input, and saturating u32::from(r.user_data).saturating_add(r.sgprs) before .clamp(8, 104) produces the exact 10..=106 initialized SGPR count expected by Lower::inputs. The regression test covers both overflow cases. LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3076#pullrequestreview-6070406411) · **approved these changes** Tested locally on Windows 11 x64 (`rustc 1.98.1`): - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean. - `cargo test -p victory-shader --locked io::tests`: 5 passed, 0 failed. The VS `checked_add` cleanly rejects `u8` register-number overflow while preserving `v255` as a valid single-channel input, and saturating `u32::from(r.user_data).saturating_add(r.sgprs)` before `.clamp(8, 104)` produces the exact `10..=106` initialized SGPR count expected by `Lower::inputs`. The regression test covers both overflow cases. LGTM.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:22 UTC · original

Automated triage for the maintainers.

Proposed close: this guards cases that valid shader metadata cannot produce. In io::raise, i.vgpr + channel can only overflow when a vertex input starts at v253 or higher and still has a channel past v255, which is past the 256-VGPR file. u32::from(r.user_data) + r.sgprs can only overflow when a root parameter claims about 4 billion user SGPRs, and the result is clamped to 104 anyway. The new test builds exactly these records by hand (vgpr: 255, sgprs: u32::MAX). No real metadata reaches them. CI: not run.

Evidence that a real FSSM record reaches either path (for example a parser path that yields such values from well-formed data) would change this verdict.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3076#issuecomment-7186510882) <!-- victory-triage v1 head=e1ac79d83fafc6af191db3623713c89add938d09 verdict=proposed-close at=2026-11-26T08:18:02Z --> Automated triage for the maintainers. Proposed close: this guards cases that valid shader metadata cannot produce. In `io::raise`, `i.vgpr + channel` can only overflow when a vertex input starts at v253 or higher and still has a channel past v255, which is past the 256-VGPR file. `u32::from(r.user_data) + r.sgprs` can only overflow when a root parameter claims about 4 billion user SGPRs, and the result is clamped to 104 anyway. The new test builds exactly these records by hand (`vgpr: 255`, `sgprs: u32::MAX`). No real metadata reaches them. CI: not run. Evidence that a real FSSM record reaches either path (for example a parser path that yields such values from well-formed data) would change this verdict. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 11:09:47 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 09:32 UTC · original

Closing per triage feedback: valid FSSM metadata cannot produce the overflowing vgpr or sgprs values guarded here. Thanks for the review! Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 09:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3076#issuecomment-7188117950) Closing per triage feedback: valid FSSM metadata cannot produce the overflowing `vgpr` or `sgprs` values guarded here. Thanks for the review! Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Pull request closed

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