GPU/descriptor: validate buffer extent/view in own_bytes and require 16-byte alignment for raw views #803

Open
github-bot wants to merge 1 commit from github-bot/gh-803 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 08:19 UTC · original
AscilCH:fix/gpu-descriptor-own-bytes-bounds-and-raw-align → main · +187 −32 · 1 files · 1 commits · open

Summary

Fix two own_bytes() / own_bytes_if() bugs introduced in a26859f (crates/victory-gpu/src/descriptor/host.rs):

  1. Validate buffer extent and view validity before calling shadow::exact().

    • own_bytes_if() previously checked only element > 0 && count > 0 and offset % element != 0, without checking (first + count) * element <= len (the title buffer's actual extent) or buffer_view_ok.
    • Out-of-bounds or invalid console views (including zero-length placed buffers) could allocate arbitrary-sized exact copies via shadow::exact(), after which buffer_srv()/buffer_uav() ran buffer_view_ok against the newly allocated exact buffer's width instead of the title buffer's len, completely bypassing the bounds check.
    • Pass the title buffer's len and DXGI_FORMAT into own_bytes() / own_bytes_if() and require len > 0, (first + count) * element <= len, and buffer_view_ok (including structured-to-raw conversion via raw_window) before allocating an exact copy.
  2. Enforce D3D12's 16-byte alignment requirement for RAW buffer SRVs/UAVs in own_bytes().

    • own_bytes_if() previously checked only offset.is_multiple_of(element) (4 bytes for R32_TYPELESS RAW views), ignoring buffer_view_ok's 16-byte raw alignment check (first.is_multiple_of(4)).
    • Valid raw views at offsets 4, 8, or 12 mod 16 returned None, shifted FirstElement by offset / 4, failed buffer_view_ok, and were left NULL.
    • Require offset.is_multiple_of(4) && (first + offset / 4).is_multiple_of(4) for raw views to stay on the whole buffer copy, routing misaligned raw views to shadow::exact() starting at FirstElement = 0.

Verification

  • cargo test -p victory-gpu --locked -- descriptor::: 30 passed; 0 failed; 0 ignored, including new out_of_bounds_and_invalid_views_do_not_allocate_exact_copies and raw_views_off_16_byte_alignment_get_exact_copies.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in crates/victory-gpu/src/descriptor/host.rs (only pre-existing 9376fd6 warnings in draw.rs and indirect.rs).
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 08:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/803) `AscilCH:fix/gpu-descriptor-own-bytes-bounds-and-raw-align` → `main` · +187 −32 · 1 files · 1 commits · open ## Summary Fix two `own_bytes()` / `own_bytes_if()` bugs introduced in `a26859f` (`crates/victory-gpu/src/descriptor/host.rs`): 1. **Validate buffer extent and view validity before calling `shadow::exact()`.** - `own_bytes_if()` previously checked only `element > 0 && count > 0` and `offset % element != 0`, without checking `(first + count) * element <= len` (the title buffer's actual extent) or `buffer_view_ok`. - Out-of-bounds or invalid console views (including zero-length placed buffers) could allocate arbitrary-sized `exact` copies via `shadow::exact()`, after which `buffer_srv()`/`buffer_uav()` ran `buffer_view_ok` against the newly allocated `exact` buffer's width instead of the title buffer's `len`, completely bypassing the bounds check. - Pass the title buffer's `len` and `DXGI_FORMAT` into `own_bytes()` / `own_bytes_if()` and require `len > 0`, `(first + count) * element <= len`, and `buffer_view_ok` (including structured-to-raw conversion via `raw_window`) before allocating an `exact` copy. 2. **Enforce D3D12's 16-byte alignment requirement for RAW buffer SRVs/UAVs in `own_bytes()`.** - `own_bytes_if()` previously checked only `offset.is_multiple_of(element)` (4 bytes for `R32_TYPELESS` `RAW` views), ignoring `buffer_view_ok`'s 16-byte raw alignment check (`first.is_multiple_of(4)`). - Valid raw views at offsets 4, 8, or 12 mod 16 returned `None`, shifted `FirstElement` by `offset / 4`, failed `buffer_view_ok`, and were left NULL. - Require `offset.is_multiple_of(4) && (first + offset / 4).is_multiple_of(4)` for raw views to stay on the whole buffer copy, routing misaligned raw views to `shadow::exact()` starting at `FirstElement = 0`. ## Verification - `cargo test -p victory-gpu --locked -- descriptor::`: `30 passed; 0 failed; 0 ignored`, including new `out_of_bounds_and_invalid_views_do_not_allocate_exact_copies` and `raw_views_off_16_byte_alignment_get_exact_copies`. - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `crates/victory-gpu/src/descriptor/host.rs` (only pre-existing `9376fd6` warnings in `draw.rs` and `indirect.rs`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
Fix two bugs in `own_bytes()` / `own_bytes_if()` (`crates/victory-gpu/src/descriptor/host.rs`):

1. Missing buffer-extent and view validity checks before `shadow::exact()`:
   `own_bytes_if()` previously checked only `element > 0 && count > 0` and
   `offset % element != 0` without verifying that `(first + count) * element <= len`
   or that the view's format/stride satisfy `buffer_view_ok`. Out-of-bounds or
   invalid console views (including zero-length placed buffers) could allocate
   arbitrary-sized `exact` copies in `shadow::exact()`, and `buffer_srv()` /
   `buffer_uav()` then checked `buffer_view_ok` against the newly allocated
   `exact` buffer's width instead of the title buffer's actual `len`, bypassing
   the bounds check completely. Validate `len > 0`, `(first + count) * element <= len`,
   and `buffer_view_ok` (including structured-to-raw conversion via `raw_window`)
   before returning `Some((start, bytes))`.

2. Missing 16-byte alignment check for RAW buffer SRVs/UAVs:
   `own_bytes_if()` checked only `offset.is_multiple_of(element)` (4 bytes for
   `R32_TYPELESS` `RAW` views), ignoring D3D12's 16-byte alignment requirement
   enforced by `buffer_view_ok` (`first.is_multiple_of(4)`). Valid raw buffer
   views at offsets 4, 8, or 12 mod 16 returned `None`, added `offset / 4` to
   `FirstElement`, failed `buffer_view_ok`, and were left NULL. Require
   `offset.is_multiple_of(4) && (first + offset / 4).is_multiple_of(4)` for raw
   views to stay on the whole copy, routing misaligned raw views to `shadow::exact()`.

Add `out_of_bounds_and_invalid_views_do_not_allocate_exact_copies` and
`raw_views_off_16_byte_alignment_get_exact_copies` to `own_copy_tests`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:29 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-25 09:54 UTC · original

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head ba5600d into main 9376fd6 in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails, with the same two errors as main itself on this machine (function placed_filler_twins is never used, field depth_written is never read, victory-gpu): this PR adds none and removes none. cargo test --workspace --locked: 542 passed, 0 failed, 10 ignored, two runs (main alone: 540 passed). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-25 09:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/803#issuecomment-7158953866) Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head `ba5600d` into `main` `9376fd6` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings` fails, with the same two errors as `main` itself on this machine (`function placed_filler_twins is never used`, `field depth_written is never read`, `victory-gpu`): this PR adds none and removes none. `cargo test --workspace --locked`: 542 passed, 0 failed, 10 ignored, two runs (`main` alone: 540 passed). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/803/head:github-bot/gh-803'
git switch 'github-bot/gh-803'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-803'
git switch 'github-bot/gh-803'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-803'
git switch 'github-bot/gh-803'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-803'
git switch 'main'
git merge --squash 'github-bot/gh-803'
git switch 'main'
git merge --ff-only 'github-bot/gh-803'
git switch 'main'
git merge 'github-bot/gh-803'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.