GPU: check overflow and SizeInBytes truncation in State::rectangles #2444
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2446"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T13:39:12Z.
Problem
In
crates/victory-gpu/src/draw.rs,State::rectangles()validates each bound vertex buffer before scheduling triangle expansion into scratch memory:u64::from(first + count) * stride > u64::from(v.size)addsfirst + countinu32before widening tou64(panicking in debug builds or wrapping in release builds and bypassing thev.sizecheck).v.address + u64::from(first) * stride(and the end of the source slicefrom + src_bytes) uses uncheckedu64arithmetic.D3D12_VERTEX_BUFFER_VIEW::SizeInBytescasts(rects * 6 * stride as u64) as u32, silently truncating if the expanded 2x triangle buffer exceedsu32::MAXwhile the source fit inv.size.Change
rect_vertex_range(v: VertexView, first: u32, count: u32) -> Option<(u64, u64, u32)>, performing widenedu64and checked arithmetic forfirst_bytes,(first + count) * stride,v.address + first_bytes,from + src_bytes, andu32::try_fromfordst_bytes.State::rectangles()to reject the draw cleanly (sameonce!warning andreturn falsepath as out-of-bounds views) whenrect_vertex_rangereturnsNone, and passdst_bytesdirectly tolist.scratchandD3D12_VERTEX_BUFFER_VIEW::SizeInBytes.Test
rect_vertex_range_rejects_u32_wrap_address_overflow_and_size_truncation(syntheticVertexViewvalues, no GPU or game data required):Some((0x1030, 48, 96)).first = u32::MAX, count = 3(u32wrap) returnsNone.v.address = u64::MAX - 8withfirst = 1andfirst = 0(u64address overflow on start and end) returnsNone.u32::MAX(0xC000_0000bytes) but whose 2x expanded buffer (0x1_8000_0000bytes) overflowsu32returnsNone.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:57:21Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:SizeInBytestruncation inState::rectanglescleanly rejects wrapping/overflowing vertex ranges.cargo test -p victory-gpu draw::tests: 6/6 passed on RTX 5090, 6/6 passed on WARP (includingrect_vertex_range_rejects_u32_wrap_address_overflow_and_size_truncation).cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:21Z.
Review: COMMENTED
Overflow + SizeInBytes truncation checked in StateObject. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:01:36Z.
Automated triage for the maintainers.
Proposed close: the checks added to
State::rectanglesincrates/victory-gpu/src/draw.rs(rect_vertex_range) cover inputs the title does not produce (a buffer address near the top of the 64-bit range, a start vertex near 2^32, an expansion over 4 GiB), and on main such ranges are already refused bycrate::shadow::findor the scratch allocation. If a real draw from the title reaches one of these paths, please describe it. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. CI: passing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T16:10:18Z.
Fair point — these overflow cases aren't hit by real title draws and shadow::find / list.scratch already reject out-of-range spans on main. Closing to keep the queue clean.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:52:27Z.
Verified the arithmetic: the old code had a real u32 wrap —
u64::from(first + count)added in u32 first, sofirst=u32::MAXwrapped to 2 and bypassed thev.sizebound; plusrects * 6 * stridetruncated to u32 silently forSizeInBytes. The newchecked_*chain covers both, and the semantics match the original (bound byfirst + counteven though onlyrects * 3vertices are read — conservative, unchanged). Test vectors check out ((3,3)→0x1030/48/96).Pull request closed