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

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

@⁠itzzArshad on GitHub · 2026-11-24 05:42 UTC · original
itzzArshad:fix/gpu-rect-bounds-overflow → main · +68 −11 · 1 files · 2 commits · open

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.

**@⁠itzzArshad** on GitHub · 2026-11-24 05:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/616) `itzzArshad:fix/gpu-rect-bounds-overflow` → `main` · +68 −11 · 1 files · 2 commits · open 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.
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.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review on #616: the test module sat before items, which clippy's
items_after_test_module rejects under -D warnings; and the rectangle
source address is now a checked add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:11 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 10:50 UTC · original

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 10:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7129314101) 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.*
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 13:32 UTC · original

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.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 13:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7132972038) 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.
Author
Owner

@⁠Yaekai on GitHub · 2026-11-24 16:15 UTC · original

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!
**@⁠Yaekai** on GitHub · 2026-11-24 16:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7137359330) 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!
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/616#issuecomment-7148586727) <!-- 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/616/head:github-bot/gh-616'
git switch 'github-bot/gh-616'

Merge

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