fix(gpu): guard rectangle vertex expansion against bounds overflow and partial slot updates #3371
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3371
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@reeledMarek on GitHub · 2026-11-26 20:40 UTC · original
reeledMarek:fix/gpu-rectangles-bounds-overflow→main· +90 −12 · 1 files · 1 commits · openSummary
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 --locked@Dukestar69 on GitHub · 2026-11-26 20:47 UTC · original · approved these changes
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).
@fuzeofficlal on GitHub · 2026-11-26 21:11 UTC · original · approved these changes
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!
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.