Repository navigation
GPU: reject overflowing rectangle vertex ranges - #2727
fuzeofficlal wants to merge 1 commit into
Conversation
|
All the overflow paths closed correctly: first+count widened to u64 before adding, checked_mul on every product, checked_add on addresses, try_from for SizeInBytes. Especially good that expanded_rectangle_vertices is computed before prepare/run so the draw-side count can't overflow after rectangles() already succeeded, and a None count falls into not_run rather than silently drawing a truncated count. Per-slot once! rejection still names the slot. |
|
Independent WARP/CPU verification of Review: Every arithmetic step in Results (WARP/CPU):
Negative control (mutating the production code on the PR head):
Method: no physical GPU. AI disclosure: this verification was done by Claude Code / Claude Sonnet 5.5. |
|
Thanks for the independent verification and negative-control check! Good observation on |
|
I found a separate valid range that still gets dropped on 6faf2e0 is one commit on your exact HEAD. It keeps the checked arithmetic, accepts the final vertex when its declared attributes fit, and initializes the missing scratch padding to zero. The same guest rectangle draw and texture readback return two clear texels on main Please keep my Git author if you cherry-pick or rebase the commit. If you fold the change or test into another commit, please add this trailer. Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com AI-assisted with Codex. Synthetic vertices on WARP. |
|
Thanks for investigating this and putting together Because an unpadded trailing vertex is a pre-existing limitation on |
|
Automated triage for the maintainers. Merge candidate (recommending a look, not an approval). Thanks for reducing it as asked. The PR is now one helper, Generated by Claude Code |
State::rectangles previously evaluated u64::from(first + count) * stride, adding first and count in u32 before widening so overflowing draw arguments could panic in debug builds (or wrap in release). Widen both operands to u64 before adding and check the expanded D3D12_VERTEX_BUFFER_VIEW::SizeInBytes conversion via rectangle_vertex_bounds.
|
Rebased onto
Verified on Windows 11 (RTX 5090 + WARP): |
f712e15 to
c5a75f7
Compare
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):
cargo test -p victory-gpu --lib draw::tests: 21 passed, 0 failed (including newrectangle_vertex_bounds_widens_first_plus_count).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Summary
Fix integer overflow, address wraparound, and
u32buffer-size truncation in CPU rectangle vertex expansion (crates/victory-gpu/src/draw.rs):State::rectanglespreviously checkedu64::from(first + count) * stride > u64::from(v.size), addingfirst + countinu32before widening — overflowing in debug builds or wrapping around in release builds to bypass thev.sizebounds check (e.g.,first = u32::MAX - 2, count = 3orfirst = 1, count = u32::MAX).v.address + u64::from(first) * stride,from + src_bytes) and byte-length calculations (rects * 3 * stride,rects * 6 * stride) lacked checked arithmetic, andD3D12_VERTEX_BUFFER_VIEW::SizeInBytessilently truncated(rects * 6 * stride) as u32when the expanded buffer exceededu32::MAX(e.g., a 3 GiB source buffer expanding to 6 GiB).State::drawcomputedvertices / 3 * 6inu32, which could overflow even on pipelines without per-vertex input slots.Extract
rectangle_vertex_rangeandexpanded_rectangle_verticesusing checked arithmetic andu32::try_from, rejecting overflowing or out-of-bounds rectangle draws cleanly before allocating scratch memory or issuingDrawInstanced.Tests
Added 6 deterministic unit tests in
crates/victory-gpu/src/draw.rscovering valid ranges,u32first + countwraparound,u64address wraparound (v.address + offsetandfrom + src_bytes),u64byte-offset multiplication overflow,u32SizeInBytestruncation (stride = 0x8000_0000and0x4000_0000), andexpanded_rectangle_verticesoverflow boundaries.Verification
cargo clippy --locked -p victory-gpu --all-targets -- -D warningsand--features diagnostics: 0 warnings.rustc 1.98.1MSVC):cargo test --locked -p victory-gpu --lib draw::tests-> 17 passed, 0 failed.VICTORY_D3D12_WARP=1):cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1-> 204 passed, 0 failed, 1 ignored.cargo xtask policy: 184 files ok.