GPU: validate allocate_upload alignments and handle oversized requests #1346

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/1346 into main
fuzeofficlal commented 2026-11-24 17:34:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:34:11Z.


Fixes #837.

Summary

  • Check raw_align != 0 && !raw_align.is_power_of_two() before clamping raw_align.max(16) in allocate_upload, rejecting invalid sub-16 non-power-of-two alignments (3, 5..15, etc.) while keeping 0 and 1, 2, 4, 8 promoted to 16-byte alignment.
  • Allocate with Vec::try_reserve_exact(len) before resize(len, 0) and guard offset >= align so oversized (> isize::MAX, u64::MAX) or OOM requests return null_mut() cleanly instead of panicking or aborting across the extern "system" FFI boundary.

Verification

  • Added list::tests::allocate_upload_validates_alignments_and_handles_oversized_requests covering null this, invalid alignments, oversized/OOM requests, valid power-of-two alignments (0, 1..4096), zero-sized allocations, and reset cleanup:
    • NVIDIA GeForce RTX 5090 (VICTORY_D3D12_DEBUG=1): passed
    • Microsoft D3D12 WARP (VICTORY_D3D12_DEBUG=1): passed
  • cargo clippy --workspace --all-targets --all-features and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587715566 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1346). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:34:11Z. --- Fixes #837. ### Summary - Check `raw_align != 0 && !raw_align.is_power_of_two()` *before* clamping `raw_align.max(16)` in `allocate_upload`, rejecting invalid sub-16 non-power-of-two alignments (`3, 5..15`, etc.) while keeping `0` and `1, 2, 4, 8` promoted to 16-byte alignment. - Allocate with `Vec::try_reserve_exact(len)` before `resize(len, 0)` and guard `offset >= align` so oversized (`> isize::MAX`, `u64::MAX`) or OOM requests return `null_mut()` cleanly instead of panicking or aborting across the `extern "system"` FFI boundary. ### Verification - Added `list::tests::allocate_upload_validates_alignments_and_handles_oversized_requests` covering null `this`, invalid alignments, oversized/OOM requests, valid power-of-two alignments (`0, 1..4096`), zero-sized allocations, and `reset` cleanup: - **NVIDIA GeForce RTX 5090** (`VICTORY_D3D12_DEBUG=1`): passed - **Microsoft D3D12 WARP** (`VICTORY_D3D12_DEBUG=1`): passed - `cargo clippy --workspace --all-targets --all-features` and `cargo xtask policy`: passed.
acetonahard-code commented 2026-11-24 20:03:07 +00:00 (Migrated from github.com)

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-gpu passed failed ignored
main 50 0 1
main + this PR 51 0 1
main, --all-features 53 0 1
main + this PR, --all-features 54 0 1
  • The new test passes.
  • Run with --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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141949340 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1346#issuecomment-7141949340). Originally posted by [acetonahard-code](https://github.com/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-gpu` | passed | failed | ignored | |---|---|---|---| | `main` | 50 | 0 | 1 | | `main` + this PR | 51 | 0 | 1 | | `main`, `--all-features` | 53 | 0 | 1 | | `main` + this PR, `--all-features` | 54 | 0 | 1 | - The new test passes. - Run with `--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. --- <sub>Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.</sub>
catminou4 commented 2026-11-24 21:02:11 +00:00 (Migrated from github.com)

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_upload now rejects null this, non-power-of-two alignments (except 0 → default 16), and uses try_reserve_exact + resize so oversized requests return null instead of aborting on allocation failure. The align_offset(align) >= align guard 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_list fixtures mirror the existing test style.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046527065 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1346#pullrequestreview-6046527065). Originally posted by [catminou4](https://github.com/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_upload` now rejects null this, non-power-of-two alignments (except 0 → default 16), and uses `try_reserve_exact` + `resize` so oversized requests return null instead of aborting on allocation failure. The `align_offset(align) >= align` guard 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_list` fixtures mirror the existing test style.
upstream-sync closed this pull request 2026-11-25 01:06:17 +00:00
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

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, or main has 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148715793 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1346#issuecomment-7148715793). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:37:59Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1346
No description provided.