GPU: validate allocate_upload alignments and handle oversized requests #1346

Closed
github-bot wants to merge 1 commit from gh-pr/1346/head into gh-pr/1346/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:34 UTC · original
fuzeofficlal:fix/allocate-upload-alignment-oom-837 → main · +85 −7 · 1 files · 1 commits · closed without merging

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1346) `fuzeofficlal:fix/allocate-upload-alignment-oom-837` → `main` · +85 −7 · 1 files · 1 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:20 +00:00
github-bot closed this pull request 2026-11-26 04:28:20 +00:00
Author
Owner

@⁠acetonahard-code on GitHub · 2026-11-24 19:20 UTC · original

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.

**@⁠acetonahard-code** on GitHub · 2026-11-24 19:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1346#issuecomment-7141949340) 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>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:37 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1346#issuecomment-7148715793) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1346
No description provided.