fix(gpu): guard rectangle vertex expansion against bounds overflow and partial slot updates #3371
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3371"
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 reeledMarek on 2026-11-26T20:40:37Z.
Summary
State::rectangles,u64::from(first + count) * stride > u64::from(v.size)evaluatedfirst + countin 32-bit arithmetic (panicking in debug or wrapping in release to bypass the bounds check),v.address + u64::from(first) * stridecould overflowu64, and(rects * 6 * stride as u64) as u32could silently truncateD3D12_VERTEX_BUFFER_VIEW::SizeInBytes(or overflow(vertices / 3) * 6inDrawInstanced).defer_hostexpansions and overwrittenIASetVertexBufferswith scratch views.rect_vertex_rangewith full checked arithmetic for bounds, addresses, and expanded sizes, and validates/allocates all slots before scheduling deferred expansions or callingIASetVertexBuffers.rect_vertex_range_rejects_overflow_and_out_of_bounds.Verification
cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warningscargo test -p xtask --lockedImported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:47:53Z.
Review: APPROVED
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21 passed, 0 failed (includingrect_vertex_range_rejects_overflow_and_out_of_bounds).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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:11:17Z.
Review: APPROVED
Clean, focused hardening of CPU rectangle vertex expansion (
crates/victory-gpu/src/draw.rs):rect_vertex_range(draw.rs:48-72) replaces unchecked 32-bitfirst + count, uncheckedv.address + first * stride, and truncating(rects * 6 * stride) as u32with checked arithmetic, preserving exact bounds behavior for valid draws with non-zerofirst.State::rectangles(draw.rs:1635-1688) now validates all active vertex slots and allocates all scratch ranges before scheduling anydefer_hostclosure or callingIASetVertexBuffers, preventing partial slot updates on failure.origin/main63bcca43):cargo xtask policy(191 files ok) andcargo clippy --locked -p victory-gpu --tests -- -D warnings(default and--features diagnostics) pass cleanly.draw::tests::*(includingrect_vertex_range_rejects_overflow_and_out_of_bounds) pass on both NVIDIA GeForce RTX 5090 and Microsoft WARP withVICTORY_D3D12_DEBUG=1.Two minor non-blocking edge notes:
rect_vertex_rangechecksv.address.checked_add(first * stride)but notfrom.checked_add(in_bytes)directly (e.g.,address = u64::MAX - 31, size = 48, stride = 16, first = 0, count = 3returnsSome((u64::MAX - 31, 48, 96)));State::rectanglesstill safely rejects it right after viashadow::find(from, in_bytes)(address.checked_add(len.max(1))?).plan.is_empty()),State::rectanglesreturnstruewithout checkingvertices / 3 * 6againstu32::MAXinState::draw(draw.rs:1576).LGTM!
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:10Z.
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:draw::tests::rect_vertex_range_rejects_overflow_and_out_of_boundsby name: 1 passed.cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.Synthetic only. AI-assisted.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.