GPU: reject overflowing rectangle vertex ranges #2727
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!2727
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2727"
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?
@fuzeofficlal on GitHub · 2026-11-25 19:01 UTC · original
fuzeofficlal:fix/gpu-rect-vertex-range-overflow→main· +34 −8 · 1 files · 1 commits · openSummary
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.@kotekompotek on GitHub · 2026-11-25 19:02 UTC · original
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.
@oni-swr on GitHub · 2026-11-25 20:58 UTC · original
Independent WARP/CPU verification of
f712e159(#2727).Review: Every arithmetic step in
rectangle_vertex_rangeis widened to u64 or checked (first+count,*stride, address add,rects*3*stride,rects*6*strideinto u32), andexpanded_rectangle_verticeschecksvertices/3*6. The draw path skips with the existing "outside their buffer" message on any failure. The unsafe slices now use the checkedsrc_bytes/dst_bytes. Scope is one file,draw.rs, and I found no correctness problems.Results (WARP/CPU):
origin/main:cargo test -p victory-gpu --lib: 195 passed, 0 failed.cargo clippy --locked -p victory-gpu --all-targets [--all-features] -- -D warnings: clean.cargo test -p xtask(policy): 6 passed.Negative control (mutating the production code on the PR head):
checked_mulreplaced bywrapping_mulinexpanded_rectangle_vertices:expanded_rectangle_vertices_rejects_overflowfails, as it should.checked_mulreplaced bywrapping_mulforend_bytesinrectangle_vertex_range: all tests still pass. The chosen overflow inputs are still rejected by the later size comparison, so none of them pins that particularchecked_mul. This is a test-coverage gap, not a bug in the PR. An input where(first+count)*stridewraps to a value belowsizewould close it.Method: no physical GPU.
VICTORY_WARP=1,VICTORY_D3D12_WARP=1, Windows SDK 10.0.26100dxil.dllonPATH, Windows 11, rustc 1.98.1 MSVC,--locked. Comparedorigin/main(13f91ca) with the PR head. The PR merges cleanly onto that main. No game files, dumps, shader names or retail hashes were used or are needed.AI disclosure: this verification was done by Claude Code / Claude Sonnet 5.5.
@fuzeofficlal on GitHub · 2026-11-25 21:21 UTC · original
Thanks for the independent verification and negative-control check! Good observation on
end_byteschecked_mul: becausefirstandcountareu32andcount >= 3requiresdst_bytes = (count / 3) * 6 * stride <= u32::MAX(forcingstride <= u32::MAX / 6),(first + count) * strideis bounded by(2^33 - 2) * (u32::MAX / 6) < 2^64for any input that passes thedst_bytescheck—sochecked_mulis defensive against future widening whiledst_bytesalready boundsstride.@andrewpozdnakov7-jpg on GitHub · 2026-11-25 21:24 UTC · original
I found a separate valid range that still gets dropped on
f712e159. A 56-byte view with a 16-byte stride starts drawing at vertex 1. Its last float2 is fully present at bytes 48–55. The same buffer renders the expected top-left pixel through the normal triangle path on WARP.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
13f91caand onf712e159. With the patch both are[1, 0, 0, 1]. The fully padded rectangle, native input-assembler triangle and 55-byte incomplete-position controls pass in all builds. Six paired Windows/WARP runs across both debug settings. The full GPU suite passed 205 tests with one ignored in each setting. Strict GPU Clippy in both configurations and asset policy also passed.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 [email protected]
AI-assisted with Codex. Synthetic vertices on WARP.
@fuzeofficlal on GitHub · 2026-11-25 21:29 UTC · original
Thanks for investigating this and putting together
6faf2e0with a concrete reproduction!Because an unpadded trailing vertex is a pre-existing limitation on
origin/main13f91caas well and spansdraw.rs,primitive.rs(expand_rects, which also overlaps #2603), andpipeline/host.rs, let's keep #2727 narrowly scoped to the arithmetic overflow/truncation checks indraw.rsso it stays small and independent for triage. Please go ahead and open6faf2e0as a standalone PR—happy to help review and run it on RTX 5090 + WARP once opened.@Marvisak on GitHub · 2026-11-25 23:16 UTC · original · edited 2026-11-26 02:16 UTC
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,
rectangle_vertex_boundsincrates/victory-gpu/src/draw.rs, used byState::rectangles: it widensfirst + countto u64 before multiplying by the stride (onmainthat add is in u32 and can panic in debug builds on bad draw arguments), and the scratch size/SizeInBytesnow come from one checkedu32::try_frominstead of a truncating cast. Theshadow::findcheck is kept, and there is one focused test. I checked it against the current loop onmain; it merges cleanly and CIcheckis passing. If #2729 lands first this will need a small rebase.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 23:31 UTC · original
Rebased onto
origin/main(842b0cb) and reduced inc5a75f7cper triage feedback:State::drawvertex-count check and the extrau64::MAX/4 GiB source-address guards.rectangle_vertex_boundscheck wideningu64::from(first) + u64::from(count)before multiplying bystrideplus the checkedSizeInBytesconversion, with one focused unit test (rectangle_vertex_bounds_widens_first_plus_count).#2729if that lands first.Verified on Windows 11 (RTX 5090 + WARP):
draw::tests(21/21 RTX 5090, 21/21 WARP),cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics), andcargo xtask policy(191 files ok).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.