GPU: rectangle draws check their bounds without 32-bit overflow #616

Open
itzzArshad wants to merge 2 commits from upstream-pr/616 into main
itzzArshad commented 2026-11-24 05:42:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by itzzArshad on 2026-11-24T05:42:02Z.


The rectangle-list bounds check added first + count in 32 bits, so a draw whose first vertex and count together pass 2^32 wrapped to a small end, passed the check, and had the CPU expansion read far outside the vertex buffer at submission (title memory that may not be mapped), or panicked in debug builds. The check is now done in 64 bits with a checked multiply by the stride.

The expanded draw's vertex count (count / 3 * 6) and its vertex view size (rects * 6 * stride) also overflowed 32 bits silently; such draws are now dropped with a warning instead of running with a wrapped count.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575467191 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616). Originally posted by [itzzArshad](https://github.com/itzzArshad) on 2026-11-24T05:42:02Z. --- The rectangle-list bounds check added `first + count` in 32 bits, so a draw whose first vertex and count together pass 2^32 wrapped to a small end, passed the check, and had the CPU expansion read far outside the vertex buffer at submission (title memory that may not be mapped), or panicked in debug builds. The check is now done in 64 bits with a checked multiply by the stride. The expanded draw's vertex count (`count / 3 * 6`) and its vertex view size (rects * 6 * stride) also overflowed 32 bits silently; such draws are now dropped with a warning instead of running with a wrapped count.
LAKSHYA-cmd-tech commented 2026-11-24 06:54:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T05:43:03Z.

Review: APPROVED


Verified and tested on Windows 11 x64 (D3D12 WARP + Hardware).

  • Tested
    ect_source: checked addition and multiplication in 64 bits ((u64::from(first) + u64::from(count)).checked_mul(stride)) cleanly prevents 32-bit integer wrap-around on boundary values (u32::MAX).
  • Tested expanded_vertices: prevents 32-bit overflow on (vertices / 3) * 6 and ensures span fits in a u32 for D3D12_VERTEX_BUFFER_VIEW.
  • All 3 unit tests (expanded_counts_fit_32_bits,
    ectangle_bounds_do_not_wrap,
    ectangle_vertices_inside_their_buffer) pass.
  • cargo test -p victory-gpu: 46 passed, 0 failed.
  • cargo clippy -p victory-gpu --lib -- -D warnings: 0 warnings.
  • cargo xtask policy: 151 files clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6034272497 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#pullrequestreview-6034272497). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T05:43:03Z. **Review:** APPROVED --- Verified and tested on Windows 11 x64 (D3D12 WARP + Hardware). - Tested ect_source: checked addition and multiplication in 64 bits ((u64::from(first) + u64::from(count)).checked_mul(stride)) cleanly prevents 32-bit integer wrap-around on boundary values (u32::MAX). - Tested expanded_vertices: prevents 32-bit overflow on (vertices / 3) * 6 and ensures span fits in a u32 for D3D12_VERTEX_BUFFER_VIEW. - All 3 unit tests (expanded_counts_fit_32_bits, ectangle_bounds_do_not_wrap, ectangle_vertices_inside_their_buffer) pass. - cargo test -p victory-gpu: 46 passed, 0 failed. - cargo clippy -p victory-gpu --lib -- -D warnings: 0 warnings. - cargo xtask policy: 151 files clean.
geiyiliyabumo commented 2026-11-24 11:04:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T10:50:27Z.


Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010, Rust 1.98.1), merged onto main (ffe310e):

  • cargo xtask policy: PASS (154 files ok)
  • cargo test -p victory-gpu --locked -- draw: 3/3 PASS (including under VICTORY_D3D12_DEBUG=1 on RX 9060 XT and WARP)
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: FAIL after clean auto-merge onto main (ffe310e)

Findings

  1. CI blocker (clippy::items-after-test-module): Although git merge succeeds without conflict against ffe310e, it leaves #[cfg(test)] mod tests (crates/victory-gpu/src/draw.rs:1226) ahead of viewports, scissors, blend_factor, and stencil_ref (draw.rs:1256-1274), which fails clippy --all-targets -- -D warnings. Moving mod tests to the end of draw.rs resolves it.
  2. Non-blocking hardening (draw.rs rectangles): .map(|offset| v.address + offset) still uses unchecked u64 addition on the guest v.address pointer; switching to .and_then(|offset| v.address.checked_add(offset)) avoids debug-mode overflow panics on malformed high addresses.

The core expanded_vertices and rect_source overflow logic and tests look solid otherwise.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129314101 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7129314101). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T10:50:27Z. --- Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver `32.0.32029.2010`, Rust `1.98.1`), merged onto `main` (`ffe310e`): - `cargo xtask policy`: PASS (`154 files ok`) - `cargo test -p victory-gpu --locked -- draw`: **3/3 PASS** (including under `VICTORY_D3D12_DEBUG=1` on RX 9060 XT and WARP) - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: **FAIL** after clean auto-merge onto `main` (`ffe310e`) ### Findings 1. **CI blocker (`clippy::items-after-test-module`)**: Although `git merge` succeeds without conflict against `ffe310e`, it leaves `#[cfg(test)] mod tests` (`crates/victory-gpu/src/draw.rs:1226`) ahead of `viewports`, `scissors`, `blend_factor`, and `stencil_ref` (`draw.rs:1256-1274`), which fails `clippy --all-targets -- -D warnings`. Moving `mod tests` to the end of `draw.rs` resolves it. 2. **Non-blocking hardening (`draw.rs` `rectangles`)**: `.map(|offset| v.address + offset)` still uses unchecked `u64` addition on the guest `v.address` pointer; switching to `.and_then(|offset| v.address.checked_add(offset))` avoids debug-mode overflow panics on malformed high addresses. The core `expanded_vertices` and `rect_source` overflow logic and tests look solid otherwise. *AI-assisted; synthetic tests only, no game files.*
mercuryVM commented 2026-11-24 12:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:20:37Z.

Review: APPROVED


Tested 94bc7cf on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 46 passed, including the three new rectangle tests. With --features diagnostics, 48 passed.

  • rect_source does first + count and the multiply by stride in u64 with checked_mul, so the old wrap past 2^32, which read far outside the vertex buffer, is gone. Every 32-bit narrowing (expanded_vertices, u32::try_from(rects * 6 * stride)) is now checked before use.
  • Nit: clippy now warns items_after_test_module at draw.rs:1191, because the new mod tests sits in the middle of the file. Moving it to the end keeps clippy as quiet as before. The other warning (host.rs:267) was already there.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038283905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#pullrequestreview-6038283905). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:20:37Z. **Review:** APPROVED --- Tested 94bc7cf on Windows 11, RTX 5070, MSVC: `cargo test -p victory-gpu -- --test-threads=1` 46 passed, including the three new rectangle tests. With `--features diagnostics`, 48 passed. - `rect_source` does `first + count` and the multiply by stride in u64 with `checked_mul`, so the old wrap past 2^32, which read far outside the vertex buffer, is gone. Every 32-bit narrowing (`expanded_vertices`, `u32::try_from(rects * 6 * stride)`) is now checked before use. - Nit: clippy now warns `items_after_test_module` at draw.rs:1191, because the new `mod tests` sits in the middle of the file. Moving it to the end keeps clippy as quiet as before. The other warning (host.rs:267) was already there. AI-assisted (Claude Code).
MichaelSmithAI commented 2026-11-24 14:04:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T13:32:14Z.


Melissa checked the accepted boundary through a rendered draw on RTX 4090 with Wine/vkd3d-proton 3.2. Head e930351 merged cleanly with ffe310e. A guest rectangle-list draw used three vertices starting at vertex 3 in a 48-byte vertex view with an 8-byte stride. Its last vertex ended exactly at the end of the view. After expansion, all 64 pixels of the 8×8 render target read back red.

All four rectangle-filtered tests passed on that integration, including both bounds tests, the fourth-corner test, and the new render readback. This checks that the revised bounds still admit a valid edge-aligned draw.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132972038 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7132972038). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T13:32:14Z. --- Melissa checked the accepted boundary through a rendered draw on RTX 4090 with Wine/vkd3d-proton 3.2. Head `e930351` merged cleanly with `ffe310e`. A guest rectangle-list draw used three vertices starting at vertex 3 in a 48-byte vertex view with an 8-byte stride. Its last vertex ended exactly at the end of the view. After expansion, all 64 pixels of the 8×8 render target read back red. All four rectangle-filtered tests passed on that integration, including both bounds tests, the fourth-corner test, and the new render readback. This checks that the revised bounds still admit a valid edge-aligned draw.
Yaekai commented 2026-11-24 17:04:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Yaekai on 2026-11-24T16:15:06Z.


Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head e930351:

  • cargo test -p victory-gpu --lib: 46 passed, 0 failed.
  • cargo clippy -p victory-gpu -- -D warnings: 0 warnings.
  • Checked arithmetic in draw.rs + new rectangle bounds unit tests: cleanly prevents 32-bit overflow in vertex/address calculations. Ready to merge!
<!-- greyfinch-sync:Marvisak/VIctory:comment:7137359330 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7137359330). Originally posted by [Yaekai](https://github.com/Yaekai) on 2026-11-24T16:15:06Z. --- Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head `e930351`: - `cargo test -p victory-gpu --lib`: 46 passed, 0 failed. - `cargo clippy -p victory-gpu -- -D warnings`: 0 warnings. - Checked arithmetic in `draw.rs` + new rectangle bounds unit tests: cleanly prevents 32-bit overflow in vertex/address calculations. Ready to merge!
Marvisak commented 2026-11-25 01:07:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:30:53Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/draw.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148586727 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7148586727). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:30:53Z. --- <!-- victory-triage v1 head=e930351bebd6df13e731021e9f6f9cbccf6e64a5 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/draw.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/616:upstream-pr/616'
git switch 'upstream-pr/616'

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