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

Closed
Dukestar69 wants to merge 1 commit from upstream-pr/3076 into main
Dukestar69 commented 2026-11-26 06:42:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:42:23Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6621098695 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3076). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:42:23Z. --- ## 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).
fuzeofficlal commented 2026-11-26 09:05:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:03:38Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6070406411 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3076#pullrequestreview-6070406411). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:03:38Z. **Review:** APPROVED --- 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.
Marvisak commented 2026-11-26 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:22:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186510882 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3076#issuecomment-7186510882). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:22:12Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-26 10:04:43 +00:00
Dukestar69 commented 2026-11-26 10:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:32:02Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188117950 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3076#issuecomment-7188117950). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T09:32:02Z. --- 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

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