GPU: guard zero/overflowing stride in expand_rects and add primitive.rs unit tests #1158
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!1158
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1158/head"
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?
@Vittorio17 on GitHub · 2026-11-24 16:18 UTC · original
Vittorio17:test/gpu-primitive-audit→main· +87 −2 · 1 files · 1 commits · closed without mergingSummary
Guards
expand_rectsincrates/victory-gpu/src/primitive.rsagainst a zero or overflowing stride, which previously panicked inchunks_exact(0)or in the6 * stridearithmetic, and adds three deterministic synthetic unit tests (7 total inprimitive.rs).Closes #1061.
Changes
Bug fix:
expand_rectsnow returns early whenstride == 0or whenstride.checked_mul(3)/stride.checked_mul(6)overflows, before any slice arithmetic.Tests added (+3 synthetic, 7 total):
zero_or_overflowing_stride_is_ignored_without_panicking: zero andusize::MAX / 2strides leave the destination untouched.unorm16_unorm8_clamping_and_unknown_formats_expand_correctly: UNORM16 arithmetic, UNORM8 clamping below 0 / above 1, and an unknown format keeping the first vertex's bytes.multiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence: two rectangles ofR32G32B32_FLOATplusR16G16_FLOAT, checking both fourth corners.Synthetic tests only; no fixtures or game data.
Verification (Windows 11 x64 MSVC, Rust 1.98.1)
rustfmt --edition 2024 --check crates/victory-gpu/src/primitive.rs: PASScargo xtask policy: PASS (154 files ok)cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: PASS (0 warnings)cargo clippy -p victory-gpu --all-targets --locked --features diagnostics -- -D warnings: PASS (0 warnings)cargo test -p victory-gpu --locked -- "primitive::tests": 7 passed, 0 failedCherry-picked from
geiyiliyabumo/VIctory@e3c9dd0(branchtest/gpu-primitive-audit), as suggested in the issue.@DaniiL35 on GitHub · 2026-11-24 16:18 UTC · original
Independent Verification Review
Audited
expand_rectsarithmetic and slice chunking invariants incrates/victory-gpu/src/primitive.rs:Zero-Stride & Overflow Panic Invariant:
chunks_exact(0)andchunks_exact_mut(0)panic immediately (assert!(chunk_size != 0)).stride == 0or an out-of-range stride where3 * strideoverflowsusize, previous code panicked.stride == 0andchecked_mul(3)/checked_mul(6)cleanly protects geometry expansion without allocating or panicking.Test Quality & Cross-Platform Execution:
zero_or_overflowing_stride_is_ignored_without_panicking,unorm16_unorm8_clamping_and_unknown_formats_expand_correctly, andmultiple_rectangles_and_f32_f16_vector_formats_expand_in_sequence) verify UNORM clamping, fourth-vertex extrapolation (v0 + v2 - v1), and raw fallback behavior.PR is clean, minimal, and ready to merge.
@Zipettte on GitHub · 2026-11-24 18:01 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
abefa49:cargo test -p victory-gpupasses, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@Marvisak on GitHub · 2026-11-25 00:33 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1204.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed