GPU: reject non-power-of-two alignments in allocate_upload #2104

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2106 into main
fuzeofficlal commented 2026-11-25 05:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T05:05:54Z.


Closes #837.

Summary

  • Check alignment != 0 && !alignment.is_power_of_two() in list::allocate_upload (crates/victory-gpu/src/list.rs) before clamping .max(16), so sub-16 non-power-of-two alignments (3, 5..=7, 9..=15, etc.) are rejected instead of being silently rounded up to 16 while 0 and powers of two continue to allocate memory aligned to max(alignment, 16).

Verification

  • list::tests::allocate_upload_validates_alignment_and_size_overflow: verifies non-zero non-power-of-two alignments and overflowing sizes return null without recording an upload block, while 0 and valid power-of-two alignments return zeroed memory aligned to max(alignment, 16).
  • cargo clippy -p victory-gpu --tests --locked -- -D warnings and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6597627537 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2106). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T05:05:54Z. --- Closes #837. ### Summary - Check `alignment != 0 && !alignment.is_power_of_two()` in `list::allocate_upload` (`crates/victory-gpu/src/list.rs`) before clamping `.max(16)`, so sub-16 non-power-of-two alignments (`3`, `5..=7`, `9..=15`, etc.) are rejected instead of being silently rounded up to 16 while `0` and powers of two continue to allocate memory aligned to `max(alignment, 16)`. ### Verification - `list::tests::allocate_upload_validates_alignment_and_size_overflow`: verifies non-zero non-power-of-two alignments and overflowing sizes return null without recording an upload block, while `0` and valid power-of-two alignments return zeroed memory aligned to `max(alignment, 16)`. - `cargo clippy -p victory-gpu --tests --locked -- -D warnings` and `cargo xtask policy`: passed.
DenRakEiw commented 2026-11-25 06:02:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T05:18:18Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib allocate_upload — passed (allocate_upload_rejects_bad_alignments_and_oversized_requests)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean validation of sub-16 alignments and oversized allocation requests in allocate_upload. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052219256 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2106#pullrequestreview-6052219256). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T05:18:18Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib allocate_upload` — passed (`allocate_upload_rejects_bad_alignments_and_oversized_requests`) - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean validation of sub-16 alignments and oversized allocation requests in `allocate_upload`. Looks good. AI-assisted (Gemini 4 Neon).
upstream-sync changed title from [PR #2106] GPU: validate sub-16 alignments and guard oversized requests in allocate_upload to [PR #2106] GPU: reject non-power-of-two alignments in allocate_upload 2026-11-25 11:04:06 +00:00
Marvisak commented 2026-11-25 11:05:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:40:41Z.


Automated triage for the maintainers.

Merge candidate.

list::allocate_upload in crates/victory-gpu/src/list.rs now rejects a non-zero, non-power-of-two alignment before clamping it to 16, so values like 3 or 12 no longer get silently rounded up. 0 and powers of two still allocate at max(alignment, 16). The new test allocate_upload_validates_alignment_and_size_overflow checks bad alignments and overflowing sizes return null with no upload block recorded, and valid alignments return zeroed, correctly aligned memory. It uses the existing helpers (create_allocator, create_list, close, reset, uploads) the same way the other tests in that module do. CI is passing.

On your reply: thanks, the head changed to 1be45cbf and it does what you said. The unreachable offset >= align check and the non-Windows Upload::new changes are gone, and the test no longer has the info-queue and shadow setup.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160023440 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2106#issuecomment-7160023440). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:40:41Z. --- <!-- victory-triage v1 head=1be45cbff86ce3644bc2b1e3ff7f0dcad4d737b1 verdict=merge-candidate at=2026-11-25T11:23:47Z --> Automated triage for the maintainers. **Merge candidate.** `list::allocate_upload` in `crates/victory-gpu/src/list.rs` now rejects a non-zero, non-power-of-two `alignment` before clamping it to 16, so values like `3` or `12` no longer get silently rounded up. `0` and powers of two still allocate at `max(alignment, 16)`. The new test `allocate_upload_validates_alignment_and_size_overflow` checks bad alignments and overflowing sizes return null with no upload block recorded, and valid alignments return zeroed, correctly aligned memory. It uses the existing helpers (`create_allocator`, `create_list`, `close`, `reset`, `uploads`) the same way the other tests in that module do. CI is passing. On your reply: thanks, the head changed to `1be45cbf` and it does what you said. The unreachable `offset >= align` check and the non-Windows `Upload::new` changes are gone, and the test no longer has the info-queue and `shadow` setup. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-25 11:05:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:49:42Z.


Updated in 1be45cbf per triage feedback:

  • Removed the unreachable offset >= align check and reverted the non-Windows Upload::new (isize::MAX / try_reserve_exact) changes back to main.
  • Trimmed the test down to the CPU-side allocate_upload alignment and overflow cases (allocate_upload_validates_alignment_and_size_overflow), removing the info-queue and shadow GPU readback setup.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7160226332 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2106#issuecomment-7160226332). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T10:49:42Z. --- Updated in `1be45cbf` per triage feedback: - Removed the unreachable `offset >= align` check and reverted the non-Windows `Upload::new` (`isize::MAX` / `try_reserve_exact`) changes back to `main`. - Trimmed the test down to the CPU-side `allocate_upload` alignment and overflow cases (`allocate_upload_validates_alignment_and_size_overflow`), removing the info-queue and `shadow` GPU readback setup.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2106:upstream-pr/2106'
git switch 'upstream-pr/2106'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2106'
git switch 'upstream-pr/2106'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2106'
git switch 'upstream-pr/2106'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2106'
git switch 'main'
git merge --squash 'upstream-pr/2106'
git switch 'main'
git merge --ff-only 'upstream-pr/2106'
git switch 'main'
git merge 'upstream-pr/2106'
git push origin 'main'
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!2104
No description provided.