GPU: validate allocate_upload alignments and handle oversized requests #1346
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1346"
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 fuzeofficlal on 2026-11-24T17:34:11Z.
Fixes #837.
Summary
raw_align != 0 && !raw_align.is_power_of_two()before clampingraw_align.max(16)inallocate_upload, rejecting invalid sub-16 non-power-of-two alignments (3, 5..15, etc.) while keeping0and1, 2, 4, 8promoted to 16-byte alignment.Vec::try_reserve_exact(len)beforeresize(len, 0)and guardoffset >= alignso oversized (> isize::MAX,u64::MAX) or OOM requests returnnull_mut()cleanly instead of panicking or aborting across theextern "system"FFI boundary.Verification
list::tests::allocate_upload_validates_alignments_and_handles_oversized_requestscovering nullthis, invalid alignments, oversized/OOM requests, valid power-of-two alignments (0, 1..4096), zero-sized allocations, andresetcleanup:VICTORY_D3D12_DEBUG=1): passedVICTORY_D3D12_DEBUG=1): passedcargo clippy --workspace --all-targets --all-featuresandcargo xtask policy: passed.Imported from Marvisak/VIctory. Originally posted by acetonahard-code on 2026-11-24T19:20:19Z.
Tested this on a GPU with SM 6.6 support (RTX 4070 SUPER, driver 621.14, Windows 11, repo toolchain), merged into current
main(ffe310e).cargo test -p victory-gpumainmain+ this PRmain,--all-featuresmain+ this PR,--all-features--nocapture, and no "no SM 6.6 ... device; skipped" lines were printed, so no GPU test skipped for lack of a device.cargo clippy --all-targets -- -D warnings, with and without--all-features: clean.I didn't test with game data.
Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:07:43Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS, so this is source review plus the PR's own Windows tests.
allocate_uploadnow rejects null this, non-power-of-two alignments (except 0 → default 16), and usestry_reserve_exact+resizeso oversized requests return null instead of aborting on allocation failure. Thealign_offset(align) >= alignguard is defensive but harmless. The test is thorough: bad alignments (3,5,6,...,u64::MAX), huge sizes (isize::MAX, 1<<50 on 64-bit), zero-length, and valid alignments 0..4096 checking alignment and zeroed contents.create_allocator/create_listfixtures mirror the existing test style.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:37:59Z.
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Hardens the old Vec-based body of allocate_upload (try_reserve, alignment order); main rewrote it on VirtualAlloc2 in [4 GiB, 2^40), which already returns null on failure. What is left (alignment 3 taken as 16) cannot matter.
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