GPU: OMSetRenderTargets dereferences invalid handles on empty or null single-range calls (fix on a fork) #796

Open
opened 2026-11-26 04:13:59 +00:00 by github-bot · 3 comments
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 11:06 UTC · original

Summary

In crates/victory-gpu/src/list.rs (state::targets, implementing ID3D12GraphicsCommandList::OMSetRenderTargets), the RTsSingleHandleToDescriptorRange != 0 path has four bugs:

  1. Access violation on count == 0 with non-null handles: if one_range != 0 && !handles.is_null() dereferences unsafe { *handles } even when NumRenderTargetDescriptors == 0 (unlike items(handles, count) right above it, which guards count == 0). In D3D12, depth-only passes may call OMSetRenderTargets(0, pRTVs, TRUE, &dsv) with an unread/stale non-null pointer; verified on host Windows 11 D3D12 that OMSetRenderTargets(0, 0x10, true, None) succeeds without dereferencing the pointer.
  2. Access violation when *handles == 0 and count >= 2: stepping first + 128 * i from a null handle 0 produces 0x80, 0x100, ..., which descriptor::rtv_record then treats as non-null pointers and dereferences in the null page (0xC0000005).
  3. Unchecked u64 arithmetic: first + 128 * i panics in debug builds (and wraps to low memory in release) if first is near u64::MAX.
  4. Unbounded count: count was not capped at D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT (8), allowing excessive allocation or invalid counts to reach the host command list.

Fix on fork

Extracted state::target_handles in crates/victory-gpu/src/list.rs to ignore handles when count == 0, cap count at 8, preserve null slots (vec![0; count]) when a single range starts at 0, and check first.checked_add(128 * i) against overflow.

Verification

  • Added synthetic regression test list::tests::om_set_render_targets_guards_empty_and_null_single_ranges (verified on origin/main before the fix: host Windows 11 D3D12 accepts the empty single-range call while state::targets crashes with 0xc0000005 STATUS_ACCESS_VIOLATION; passes after the fix).
  • cargo test -p victory-gpu: 51 passed, 0 failed, 1 ignored
  • cargo test -p victory-gpu --features diagnostics: 54 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean
  • cargo check -p victory --features diagnostics: clean
  • cargo xtask policy: 154 files ok
  • rustfmt --edition 2024 --check crates/victory-gpu/src/list.rs: 0 diffs on touched lines (pre-existing untouched diffs only)

Disclosure

  • Tested with synthetic unit tests only (no game files or console SDK data).
  • Prepared with AI assistance (Google Antigravity); PR creation is currently restricted to collaborators (#717), so sharing the branch here for whenever PRs reopen or if a maintainer wants to cherry-pick it.
**@⁠AndyLatimer** on GitHub · 2026-11-24 11:06 UTC · [original](https://github.com/Marvisak/VIctory/issues/796) ### Summary In `crates/victory-gpu/src/list.rs` (`state::targets`, implementing `ID3D12GraphicsCommandList::OMSetRenderTargets`), the `RTsSingleHandleToDescriptorRange != 0` path has four bugs: 1. **Access violation on `count == 0` with non-null `handles`**: `if one_range != 0 && !handles.is_null()` dereferences `unsafe { *handles }` even when `NumRenderTargetDescriptors == 0` (unlike `items(handles, count)` right above it, which guards `count == 0`). In D3D12, depth-only passes may call `OMSetRenderTargets(0, pRTVs, TRUE, &dsv)` with an unread/stale non-null pointer; verified on host Windows 11 D3D12 that `OMSetRenderTargets(0, 0x10, true, None)` succeeds without dereferencing the pointer. 2. **Access violation when `*handles == 0` and `count >= 2`**: stepping `first + 128 * i` from a null handle `0` produces `0x80, 0x100, ...`, which `descriptor::rtv_record` then treats as non-null pointers and dereferences in the null page (`0xC0000005`). 3. **Unchecked `u64` arithmetic**: `first + 128 * i` panics in debug builds (and wraps to low memory in release) if `first` is near `u64::MAX`. 4. **Unbounded `count`**: `count` was not capped at `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` (`8`), allowing excessive allocation or invalid counts to reach the host command list. ### Fix on fork - Branch: `AndyLatimer/VIctory` @ `fix/gpu-om-set-render-targets-bounds` (based on `main` `ffe310e`) - Commit: https://github.com/AndyLatimer/VIctory/commit/de663d2 Extracted `state::target_handles` in `crates/victory-gpu/src/list.rs` to ignore `handles` when `count == 0`, cap `count` at `8`, preserve null slots (`vec![0; count]`) when a single range starts at `0`, and check `first.checked_add(128 * i)` against overflow. ### Verification - Added synthetic regression test `list::tests::om_set_render_targets_guards_empty_and_null_single_ranges` (verified on `origin/main` before the fix: host Windows 11 D3D12 accepts the empty single-range call while `state::targets` crashes with `0xc0000005` `STATUS_ACCESS_VIOLATION`; passes after the fix). - `cargo test -p victory-gpu`: 51 passed, 0 failed, 1 ignored - `cargo test -p victory-gpu --features diagnostics`: 54 passed, 0 failed, 1 ignored - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean - `cargo check -p victory --features diagnostics`: clean - `cargo xtask policy`: 154 files ok - `rustfmt --edition 2024 --check crates/victory-gpu/src/list.rs`: 0 diffs on touched lines (pre-existing untouched diffs only) ### Disclosure - Tested with synthetic unit tests only (no game files or console SDK data). - Prepared with AI assistance (Google Antigravity); PR creation is currently restricted to collaborators (#717), so sharing the branch here for whenever PRs reopen or if a maintainer wants to cherry-pick it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:59 +00:00
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 11:08 UTC · original

Cherry-picked and merged downstream in https://github.com/LAKSHYA-cmd-tech/VIctory/pull/10.

Verified clean on Windows 11 D3D12 runtime across all 86 \ ictory-gpu\ tests including \list::tests::om_set_render_targets_guards_empty_and_null_single_ranges.

**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 11:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/796#issuecomment-7129714444) Cherry-picked and merged downstream in https://github.com/LAKSHYA-cmd-tech/VIctory/pull/10. Verified clean on Windows 11 D3D12 runtime across all 86 \ ictory-gpu\ tests including \list::tests::om_set_render_targets_guards_empty_and_null_single_ranges\.
Author
Owner

@⁠nopsled0x on GitHub · 2026-11-24 12:54 UTC · original

I checked fix/gpu-om-set-render-targets-bounds (de663d2, on top of ffe310e) on Windows 10, debug build:

  • cargo test -p victory-gpu --locked -- om_set_render_targets: 1/1 pass (om_set_render_targets_guards_empty_and_null_single_ranges), on my machine, which has a real GPU. The test does not print whether its host D3D12 section ran, so I cannot say it was exercised.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.
  • From reading the diff: the four listed cases look handled, and I found no new panic path inside the extern "system" function. A zero handle is skipped by tagged_record (descriptor.rs) without reading memory.
  • Observations from reading the code (not tested):
    • The cap at 8 now also applies to the non-single-range path, so a count above 8 is truncated silently instead of reaching the host.
    • When a handle becomes 0 (null base or overflow), set_targets skips that slot and the following render targets shift down one position. Skipping slots without a recorded view (and the resulting shift) already happened before the diff; the change only adds new cases that hit it. The open PR #450 ("preserve typed null render target slots") addresses a related slot shift for typed null RTVs; I have not checked how it interacts with this diff.
    • The test's host section only shows that the runtime did not crash with count 0 and a dangling pointer; the comment calling it the host's "contract" claims more than that.

Not verified: --features diagnostics, cargo test --workspace, xtask policy, workspace-wide clippy, or in-game behavior.

AI-assisted verification (Claude); tests were run locally by me.

**@⁠nopsled0x** on GitHub · 2026-11-24 12:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/796#issuecomment-7132080569) I checked `fix/gpu-om-set-render-targets-bounds` (de663d2, on top of ffe310e) on Windows 10, debug build: - `cargo test -p victory-gpu --locked -- om_set_render_targets`: 1/1 pass (`om_set_render_targets_guards_empty_and_null_single_ranges`), on my machine, which has a real GPU. The test does not print whether its host D3D12 section ran, so I cannot say it was exercised. - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean. - From reading the diff: the four listed cases look handled, and I found no new panic path inside the `extern "system"` function. A zero handle is skipped by `tagged_record` (`descriptor.rs`) without reading memory. - Observations from reading the code (not tested): - The cap at 8 now also applies to the non-single-range path, so a `count` above 8 is truncated silently instead of reaching the host. - When a handle becomes 0 (null base or overflow), `set_targets` skips that slot and the following render targets shift down one position. Skipping slots without a recorded view (and the resulting shift) already happened before the diff; the change only adds new cases that hit it. The open PR #450 ("preserve typed null render target slots") addresses a related slot shift for typed null RTVs; I have not checked how it interacts with this diff. - The test's host section only shows that the runtime did not crash with count 0 and a dangling pointer; the comment calling it the host's "contract" claims more than that. Not verified: `--features diagnostics`, `cargo test --workspace`, `xtask policy`, workspace-wide clippy, or in-game behavior. _AI-assisted verification (Claude); tests were run locally by me._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:53 UTC · original

Automated triage for the maintainers.

Confirmed on main: in crates/victory-gpu/src/list.rs, state::targets reads *handles whenever one_range != 0 and the pointer is non-null, even for count == 0, and expands the range as first + 128 * i with no check. From a zero first handle that yields 0x80, 0x100, ..., which rtv_record/tagged_record (descriptor.rs) dereference, since only a handle of exactly 0 is skipped. count is not capped at 8.

Open PR #1428 already carries this change (empty, null and oversized calls). Pull requests are open to everyone, so please compare your branch with #1428 and comment there, or open your own PR if yours differs. As noted in the comments, the slot shift for skipped targets overlaps with #450.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/796#issuecomment-7152335664) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T12:54:25Z at=2026-11-25T03:53:29Z --> Automated triage for the maintainers. Confirmed on `main`: in `crates/victory-gpu/src/list.rs`, `state::targets` reads `*handles` whenever `one_range != 0` and the pointer is non-null, even for `count == 0`, and expands the range as `first + 128 * i` with no check. From a zero first handle that yields 0x80, 0x100, ..., which `rtv_record`/`tagged_record` (`descriptor.rs`) dereference, since only a handle of exactly 0 is skipped. `count` is not capped at 8. Open PR #1428 already carries this change (empty, null and oversized calls). Pull requests are open to everyone, so please compare your branch with #1428 and comment there, or open your own PR if yours differs. As noted in the comments, the slot shift for skipped targets overlaps with #450. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#796
No description provided.