D3D12.X: fix null device allocation info null-deref, overflow, and RowPitch truncation #1631

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

@⁠b3IKK on GitHub · 2026-11-24 18:25 UTC · original
b3IKK:d3d12x/null-alloc-and-footprints-bounds → main · +69 −20 · 1 files · 1 commits · open

Fixes three bugs in crates/xcl/src/hle/d3d12x/null.rs:

  • Device_GetResourceAllocationInfo computed descs.add(i * 56) even when descs was null, dereferencing 0x38 on i = 1 when n >= 2 (access violation).
  • approx_size, new_resource, Device_GetResourceAllocationInfo, and Device_GetCopyableFootprints used unchecked arithmetic and aligned pointer dereferences on raw *const u8 / *mut u8 buffers, overflowing on large dimensions/widths and aborting on unaligned descriptors.
  • Device_GetCopyableFootprints multiplied buffer widths by 4 and truncated ((width * 4 + 255) & !255) as u32, turning a 1 GiB buffer's RowPitch into 0.

This guards descs.is_null(), uses saturating arithmetic and read_unaligned / write_unaligned, treats BUFFER (dim == 1) as 1 bpp, and clamps RowPitch to u32::MAX & !255.

What is in it

  • crates/xcl/src/hle/d3d12x/null.rs: guard null descs, use saturating math and unaligned reads/writes in approx_size, new_resource, Device_GetResourceAllocationInfo, and Device_GetCopyableFootprints; clamp RowPitch and handle 1-bpp buffers; add unit test null_alloc_info_and_footprints_guard_null_and_overflow.

Since the last push: rebased onto main 06c9f55; the only conflict was struct_returning_methods_take_the_buffer_first_or_second, a test main had added at the same place, and both are kept.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 1266 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib hle::d3d12x::null::tests: 4 passed, 0 failed

Regression run

main (426a5a7, clean tree, no local changes):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB

PR (ef0cb29, clean tree, no local changes):

xcl-smoke v1
commit: ef0cb29e0ac9513a1ee641013bc5bf1d23bab0aa
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1639)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15885 MB

(The main block is 426a5a7, an ancestor of the current main, from the same machine and data folder.)

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto main 06c9f55, resolved the conflicts, ran the suite and the scripts/smoke.ps1 pair at the head above.
**@⁠b3IKK** on GitHub · 2026-11-24 18:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1631) `b3IKK:d3d12x/null-alloc-and-footprints-bounds` → `main` · +69 −20 · 1 files · 1 commits · open Fixes three bugs in `crates/xcl/src/hle/d3d12x/null.rs`: - `Device_GetResourceAllocationInfo` computed `descs.add(i * 56)` even when `descs` was null, dereferencing `0x38` on `i = 1` when `n >= 2` (access violation). - `approx_size`, `new_resource`, `Device_GetResourceAllocationInfo`, and `Device_GetCopyableFootprints` used unchecked arithmetic and aligned pointer dereferences on raw `*const u8` / `*mut u8` buffers, overflowing on large dimensions/widths and aborting on unaligned descriptors. - `Device_GetCopyableFootprints` multiplied buffer widths by `4` and truncated `((width * 4 + 255) & !255) as u32`, turning a 1 GiB buffer's `RowPitch` into `0`. This guards `descs.is_null()`, uses saturating arithmetic and `read_unaligned` / `write_unaligned`, treats `BUFFER` (`dim == 1`) as 1 bpp, and clamps `RowPitch` to `u32::MAX & !255`. **What is in it** - `crates/xcl/src/hle/d3d12x/null.rs`: guard null `descs`, use saturating math and unaligned reads/writes in `approx_size`, `new_resource`, `Device_GetResourceAllocationInfo`, and `Device_GetCopyableFootprints`; clamp `RowPitch` and handle 1-bpp buffers; add unit test `null_alloc_info_and_footprints_guard_null_and_overflow`. **Since the last push**: rebased onto `main` `06c9f55`; the only conflict was `struct_returning_methods_take_the_buffer_first_or_second`, a test `main` had added at the same place, and both are kept. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): **1266 passed, 0 failed, 46 ignored** (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib hle::d3d12x::null::tests`: 4 passed, 0 failed **Regression run** main (`426a5a7`, clean tree, no local changes): ``` xcl-smoke v1 commit: 426a5a745db4d5e4b037449ede0b70cb342f5192 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15158 MB ``` PR (`ef0cb29`, clean tree, no local changes): ``` xcl-smoke v1 commit: ef0cb29e0ac9513a1ee641013bc5bf1d23bab0aa gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1639 (PresentX 1639) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15885 MB ``` (The main block is `426a5a7`, an ancestor of the current `main`, from the same machine and data folder.) **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: rebased onto `main` `06c9f55`, resolved the conflicts, ran the suite and the `scripts/smoke.ps1` pair at the head above.
Three bugs in hle/d3d12x/null.rs:
- Device_GetResourceAllocationInfo computed `descs.add(i * 56)` even
  when `descs` was null, dereferencing `0x38` on `i = 1` when `n >= 2`.
- approx_size, new_resource, Device_GetResourceAllocationInfo, and
  Device_GetCopyableFootprints used unchecked arithmetic and aligned
  pointer dereferences on raw byte pointers, overflowing on large
  dimensions/widths and faulting on unaligned descriptors.
- Device_GetCopyableFootprints multiplied buffer widths by 4 and cast
  `((width * 4 + 255) & !255) as u32`, truncating RowPitch to 0 on a
  1 GiB buffer.

Guard `descs.is_null()`, use saturating arithmetic and `read_unaligned`
/ `write_unaligned`, treat BUFFER (`dim == 1`) as 1 bpp, and clamp
RowPitch to `u32::MAX & !255`.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:00 +00:00
Author
Owner

@⁠Belox17 on GitHub · 2026-11-24 20:03 UTC · original

Test report for 30418877 on NVIDIA (RTX 3060 Ti): passes, and without the fix the test crashes with an access violation

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head 30418877 as is (base 9e3831e), clean tree.
  • The new test (null_alloc_info_and_footprints_guard_null_and_overflow) with cargo test -p xcl --lib <name>: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 777 passed, 0 failed, 41 ignored; its base 9e3831e on the same machine: 776 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Merged into current main c160d86e (clean merge): 859 passed, 0 failed, 42 ignored; main alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.
  • With the non-test hunks of hle/d3d12x/null.rs reverted (test kept), the test process ends with 0xc0000005 (STATUS_ACCESS_VIOLATION).

Not tested

  • AMD / native wave64 hardware; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.

**@⁠Belox17** on GitHub · 2026-11-24 20:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1631#issuecomment-7142969517) **Test report for `30418877` on NVIDIA (RTX 3060 Ti): passes, and without the fix the test crashes with an access violation** **Tested** - NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head `30418877` as is (base `9e3831e`), clean tree. - The new test (`null_alloc_info_and_footprints_guard_null_and_overflow`) with `cargo test -p xcl --lib <name>`: 1 passed. - `cargo test --workspace -- --test-threads=4` on the head: **777 passed, 0 failed, 41 ignored**; its base `9e3831e` on the same machine: 776 passed, 0 failed, 41 ignored. SKIPPED on both: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - Merged into current `main` `c160d86e` (clean merge): **859 passed, 0 failed, 42 ignored**; `main` alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above. - With the non-test hunks of `hle/d3d12x/null.rs` reverted (test kept), the test process ends with `0xc0000005` (`STATUS_ACCESS_VIOLATION`). **Not tested** - AMD / native wave64 hardware; any retail title (no smoke run). **AI use:** Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:46 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1631#issuecomment-7144043755) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:58 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 05:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/1631#issuecomment-7183968854) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
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/1631/head:github-bot/gh-1631'
git switch 'github-bot/gh-1631'

Merge

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