GPU: guard zero/overflowing stride in expand_rects and add primitive.rs unit tests #1158

Closed
github-bot wants to merge 1 commit from gh-pr/1158/head into gh-pr/1158/base
Owner

@⁠Vittorio17 on GitHub · 2026-11-24 16:18 UTC · original
Vittorio17:test/gpu-primitive-audit → main · +87 −2 · 1 files · 1 commits · closed without merging

Summary

Guards expand_rects in crates/victory-gpu/src/primitive.rs against a zero or overflowing stride, which previously panicked in chunks_exact(0) or in the 6 * stride arithmetic, and adds three deterministic synthetic unit tests (7 total in primitive.rs).

Closes #1061.

Changes

Bug fix: expand_rects now returns early when stride == 0 or when stride.checked_mul(3) / stride.checked_mul(6) overflows, before any slice arithmetic.

Tests added (+3 synthetic, 7 total):

  • zero_or_overflowing_stride_is_ignored_without_panicking: zero and usize::MAX / 2 strides leave the destination untouched.
  • unorm16_unorm8_clamping_and_unknown_formats_expand_correctly: UNORM16 arithmetic, UNORM8 clamping below 0 / above 1, and an unknown format keeping the first vertex's bytes.
  • multiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence: two rectangles of R32G32B32_FLOAT plus R16G16_FLOAT, checking both fourth corners.

Synthetic tests only; no fixtures or game data.

Verification (Windows 11 x64 MSVC, Rust 1.98.1)

  • rustfmt --edition 2024 --check crates/victory-gpu/src/primitive.rs: PASS
  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: PASS (0 warnings)
  • cargo clippy -p victory-gpu --all-targets --locked --features diagnostics -- -D warnings: PASS (0 warnings)
  • cargo test -p victory-gpu --locked -- "primitive::tests": 7 passed, 0 failed

Cherry-picked from geiyiliyabumo/VIctory@e3c9dd0 (branch test/gpu-primitive-audit), as suggested in the issue.

**@⁠Vittorio17** on GitHub · 2026-11-24 16:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1158) `Vittorio17:test/gpu-primitive-audit` → `main` · +87 −2 · 1 files · 1 commits · closed without merging ## Summary Guards `expand_rects` in `crates/victory-gpu/src/primitive.rs` against a zero or overflowing stride, which previously panicked in `chunks_exact(0)` or in the `6 * stride` arithmetic, and adds three deterministic synthetic unit tests (7 total in `primitive.rs`). Closes #1061. ## Changes **Bug fix**: `expand_rects` now returns early when `stride == 0` or when `stride.checked_mul(3)` / `stride.checked_mul(6)` overflows, before any slice arithmetic. **Tests added** (+3 synthetic, 7 total): - `zero_or_overflowing_stride_is_ignored_without_panicking`: zero and `usize::MAX / 2` strides leave the destination untouched. - `unorm16_unorm8_clamping_and_unknown_formats_expand_correctly`: UNORM16 arithmetic, UNORM8 clamping below 0 / above 1, and an unknown format keeping the first vertex's bytes. - `multiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence`: two rectangles of `R32G32B32_FLOAT` plus `R16G16_FLOAT`, checking both fourth corners. Synthetic tests only; no fixtures or game data. ## Verification (Windows 11 x64 MSVC, Rust 1.98.1) - `rustfmt --edition 2024 --check crates/victory-gpu/src/primitive.rs`: PASS - `cargo xtask policy`: PASS (154 files ok) - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: PASS (0 warnings) - `cargo clippy -p victory-gpu --all-targets --locked --features diagnostics -- -D warnings`: PASS (0 warnings) - `cargo test -p victory-gpu --locked -- "primitive::tests"`: 7 passed, 0 failed Cherry-picked from `geiyiliyabumo/VIctory@e3c9dd0` (branch `test/gpu-primitive-audit`), as suggested in the issue.
expand_rects now returns early when stride is zero or when 3 * stride or
6 * stride overflows, instead of panicking in chunks_exact(0) or in the
6 * stride slice arithmetic.

Adds three deterministic synthetic tests: the zero/overflow guard, UNORM16
and UNORM8 clamping with unknown formats, and multiple rectangles carrying
f32/f16 vector formats (7 tests in primitive.rs total).

Synthetic tests only; no fixtures or game data.

Cherry-picked from geiyiliyabumo/VIctory@e3c9dd0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:21:35 +00:00
github-bot closed this pull request 2026-11-26 04:21:35 +00:00
Author
Owner

@⁠DaniiL35 on GitHub · 2026-11-24 16:18 UTC · original

Independent Verification Review

Audited expand_rects arithmetic and slice chunking invariants in crates/victory-gpu/src/primitive.rs:

  1. Zero-Stride & Overflow Panic Invariant:

    • In the standard library, chunks_exact(0) and chunks_exact_mut(0) panic immediately (assert!(chunk_size != 0)).
    • If an untrusted title geometry packet supplies stride == 0 or an out-of-range stride where 3 * stride overflows usize, previous code panicked.
    • Early return via stride == 0 and checked_mul(3) / checked_mul(6) cleanly protects geometry expansion without allocating or panicking.
  2. Test Quality & Cross-Platform Execution:

    • The new tests (zero_or_overflowing_stride_is_ignored_without_panicking, unorm16_unorm8_clamping_and_unknown_formats_expand_correctly, and multiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence) verify UNORM clamping, fourth-vertex extrapolation (v0 + v2 - v1), and raw fallback behavior.
    • All tests use synthetic in-memory vertex buffers, execute cleanly without host GPU/Windows dependencies, and pass Rule #1.

PR is clean, minimal, and ready to merge.

**@⁠DaniiL35** on GitHub · 2026-11-24 16:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1158#issuecomment-7137463652) ### Independent Verification Review Audited `expand_rects` arithmetic and slice chunking invariants in `crates/victory-gpu/src/primitive.rs`: 1. **Zero-Stride & Overflow Panic Invariant**: - In the standard library, `chunks_exact(0)` and `chunks_exact_mut(0)` panic immediately (`assert!(chunk_size != 0)`). - If an untrusted title geometry packet supplies `stride == 0` or an out-of-range stride where `3 * stride` overflows `usize`, previous code panicked. - Early return via `stride == 0` and `checked_mul(3)` / `checked_mul(6)` cleanly protects geometry expansion without allocating or panicking. 2. **Test Quality & Cross-Platform Execution**: - The new tests (`zero_or_overflowing_stride_is_ignored_without_panicking`, `unorm16_unorm8_clamping_and_unknown_formats_expand_correctly`, and `multiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence`) verify UNORM clamping, fourth-vertex extrapolation (`v0 + v2 - v1`), and raw fallback behavior. - All tests use synthetic in-memory vertex buffers, execute cleanly without host GPU/Windows dependencies, and pass Rule #1. PR is clean, minimal, and ready to merge.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:01 UTC · original

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

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1158#issuecomment-7140037453) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at abefa49: `cargo test -p victory-gpu` passes, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:33 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1204.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1158#issuecomment-7148624528) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1204. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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