GPU: guard OMSetRenderTargets handle expansion on empty, null, or oversized calls #1427

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/1428 into main
fuzeofficlal commented 2026-11-24 17:57:56 +00:00 (Migrated from github.com)

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


Fixes #796.

Summary

  • Extract state::target_handles in crates/victory-gpu/src/list.rs so OMSetRenderTargets (state::targets) expands handles into a stack-allocated [u64; D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT] array:
    • Returns early when count == 0 or handles is null so OMSetRenderTargets(0, p, TRUE, &dsv) never dereferences a stale or uninitialized pRenderTargetDescriptors pointer.
    • Clamps count to D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT (8).

Verification

  • list::tests::target_handles_guards_empty_null_and_clamps_to_eight: covers count == 0 with a dangling pointer, null pointer, single-range expansion, array expansion, and clamping to 8.
  • list::tests::om_set_render_targets_zero_count_does_not_read_handles: calls vtable slot 0x190 (OMSetRenderTargets) with count == 0 and a PAGE_NOACCESS pointer (one_range = 1 with &dsv and one_range = 0 with null DSV).
  • cargo clippy -p victory-gpu --tests --locked -- -D warnings and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5477543951 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1428). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:57:56Z. --- Fixes #796. ### Summary - Extract `state::target_handles` in `crates/victory-gpu/src/list.rs` so `OMSetRenderTargets` (`state::targets`) expands handles into a stack-allocated `[u64; D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT]` array: - Returns early when `count == 0` or `handles` is null so `OMSetRenderTargets(0, p, TRUE, &dsv)` never dereferences a stale or uninitialized `pRenderTargetDescriptors` pointer. - Clamps `count` to `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` (`8`). ### Verification - `list::tests::target_handles_guards_empty_null_and_clamps_to_eight`: covers `count == 0` with a dangling pointer, null pointer, single-range expansion, array expansion, and clamping to 8. - `list::tests::om_set_render_targets_zero_count_does_not_read_handles`: calls vtable slot `0x190` (`OMSetRenderTargets`) with `count == 0` and a `PAGE_NOACCESS` pointer (`one_range = 1` with `&dsv` and `one_range = 0` with null DSV). - `cargo clippy -p victory-gpu --tests --locked -- -D warnings` and `cargo xtask policy`: passed.
Marvisak commented 2026-11-25 02:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:27:28Z.


Automated triage for the maintainers.

Merge candidate.

state::targets in crates/victory-gpu/src/list.rs now goes through state::target_handles. It returns no handles when count == 0 or handles is null, so OMSetRenderTargets(0, p, TRUE, &dsv) no longer reads *p, which is the bug in #796. It also caps count at D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT and uses a stack array in place of a Vec. The array path still goes through items, as before. The tests are short:

  • target_handles assertions for the empty, null, single-range, array and clamp cases.
  • om_set_render_targets_zero_count_does_not_read_handles, which calls vtable slot 0x190 (state::targets, entry 50 of the list vtable) with count == 0 and a PAGE_NOACCESS pointer. That test would fault on main.

CI is passing (check), and the PR merges cleanly.

On your reply: thanks, the head changed to ec57a6e and it does what the last triage asked. The rendering test is gone, the overflow and zero-base guards are dropped, and the crash is covered directly.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149567045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1428#issuecomment-7149567045). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:27:28Z. --- <!-- victory-triage v1 head=ec57a6e4793c1d78cfa601dcb4489578d6802d73 verdict=merge-candidate at=2026-11-25T11:20:11Z --> Automated triage for the maintainers. **Merge candidate.** `state::targets` in `crates/victory-gpu/src/list.rs` now goes through `state::target_handles`. It returns no handles when `count == 0` or `handles` is null, so `OMSetRenderTargets(0, p, TRUE, &dsv)` no longer reads `*p`, which is the bug in #796. It also caps `count` at `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` and uses a stack array in place of a `Vec`. The array path still goes through `items`, as before. The tests are short: - `target_handles` assertions for the empty, null, single-range, array and clamp cases. - `om_set_render_targets_zero_count_does_not_read_handles`, which calls vtable slot `0x190` (`state::targets`, entry 50 of the list vtable) with `count == 0` and a `PAGE_NOACCESS` pointer. That test would fault on `main`. CI is passing (`check`), and the PR merges cleanly. On your reply: thanks, the head changed to `ec57a6e` and it does what the last triage asked. The rendering test is gone, the overflow and zero-base guards are dropped, and the crash is covered directly. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-25 10:07:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T09:44:29Z.


Updated in ec57a6e4 per triage feedback:

  • Removed the 540-line D3DCompile/MRT rendering test and replaced the vtable coverage with om_set_render_targets_zero_count_does_not_read_handles, which calls OMSetRenderTargets (0x190) with count == 0 against a PAGE_NOACCESS page (one_range = 1 with &dsv and one_range = 0 with null DSV), alongside the pure target_handles unit checks.
  • Dropped the speculative u64::MAX overflow and zero-base checks, keeping only the count == 0 / null early return and the D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT (8) clamp.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7158736974 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1428#issuecomment-7158736974). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T09:44:29Z. --- Updated in `ec57a6e4` per triage feedback: - Removed the 540-line `D3DCompile`/MRT rendering test and replaced the vtable coverage with `om_set_render_targets_zero_count_does_not_read_handles`, which calls `OMSetRenderTargets` (`0x190`) with `count == 0` against a `PAGE_NOACCESS` page (`one_range = 1` with `&dsv` and `one_range = 0` with null DSV), alongside the pure `target_handles` unit checks. - Dropped the speculative `u64::MAX` overflow and zero-base checks, keeping only the `count == 0` / null early return and the `D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT` (`8`) clamp.
cloph-dsp commented 2026-11-27 02:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T02:05:04Z.


Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, no game data).

  • PR head ec57a6e, merge base 940d32f.
  • cargo test --locked -p victory-gpu --lib -- list::tests::target_handles_guards_empty_null_and_clamps_to_eight --exact --test-threads=1 --quiet -> test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 146 filtered out.
  • git diff --check 940d32f HEAD -> exit 0.
  • Negative control: the new test name is absent from 940d32f (git grep -c ... crates/victory-gpu/src/list.rs -> exit 1).

Note: only the named synthetic test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only list test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207817660 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1428#issuecomment-7207817660). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T02:05:04Z. --- Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, no game data). - PR head `ec57a6e`, merge base `940d32f`. - `cargo test --locked -p victory-gpu --lib -- list::tests::target_handles_guards_empty_null_and_clamps_to_eight --exact --test-threads=1 --quiet` -> `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 146 filtered out`. - `git diff --check 940d32f HEAD` -> exit 0. - Negative control: the new test name is absent from `940d32f` (`git grep -c ... crates/victory-gpu/src/list.rs` -> exit 1). Note: only the named synthetic test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only list test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.
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/1428:upstream-pr/1428'
git switch 'upstream-pr/1428'

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