D3D12.X: check vertex range overflow and SizeInBytes truncation in bind::draw_rects #1561

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

@⁠b3IKK on GitHub · 2026-11-24 17:41 UTC · original
b3IKK:d3d12x/bind-draw-rects-overflow → main · +41 −5 · 1 files · 1 commits · open

bind::draw_rects computed va as usize + first_vertex as usize * stride as usize, first_vertex as usize * s + len, and (rects * 6 * s) as u32 with unchecked arithmetic. Large title-supplied first_vertex or stride values could panic in debug builds, wrap past the > bytes bounds check in release builds, or silently truncate the expanded D3D12_VERTEX_BUFFER_VIEW::SizeInBytes.

This extracts rect_vb_range() using checked_mul, checked_add, and u32::try_from, returning false from draw_rects when any range or size check fails.

What is in it

  • crates/xcl/src/hle/d3d12x/bind.rs: add rect_vb_range(), use it in draw_rects, and add unit test rect_vb_range_rejects_overflow_and_u32_truncation.

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): 976 passed, 0 failed, 45 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 -- rect_vb_range execute_indirect: 4 passed, 0 failed (the new test and the three execute_indirect tests next to it, one of which the rebase had to be merged around)

Regression run

main (20cf130, clean tree, no local changes):

xcl-smoke v1
commit: 20cf13022f764208384c610c2ae6a3f4eed201a2
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1556)
presents per 2 s (last 3): 24 21 54
device removals: 0
crashes: 0
peak commit: 19607 MB

PR (618f4c2, clean tree, no local changes):

xcl-smoke v1
commit: 618f4c2d5417e9df54595583cdfc0a5a6f9f5728
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: 18702 MB

(The head is on 689f2db; main moved to 20cf130 while the suite ran, and the main block is that commit, run right after the PR's. Both peak higher than the blocks this PR had before, 14.6 GB: several long runs of the title on this machine in between filled its caches, and its runs now commit 17–20 GB in the first minute whatever the build. I have not isolated why.)

Not tested

  • a title that passes such a first_vertex or stride (the unit test calls rect_vb_range directly)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: audited bind.rs, wrote the fix and unit test, rebased onto 689f2db (resolving the conflict with the test main added at the same place), ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 17:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/1561) `b3IKK:d3d12x/bind-draw-rects-overflow` → `main` · +41 −5 · 1 files · 1 commits · open `bind::draw_rects` computed `va as usize + first_vertex as usize * stride as usize`, `first_vertex as usize * s + len`, and `(rects * 6 * s) as u32` with unchecked arithmetic. Large title-supplied `first_vertex` or `stride` values could panic in debug builds, wrap past the `> bytes` bounds check in release builds, or silently truncate the expanded `D3D12_VERTEX_BUFFER_VIEW::SizeInBytes`. This extracts `rect_vb_range()` using `checked_mul`, `checked_add`, and `u32::try_from`, returning `false` from `draw_rects` when any range or size check fails. **What is in it** - `crates/xcl/src/hle/d3d12x/bind.rs`: add `rect_vb_range()`, use it in `draw_rects`, and add unit test `rect_vb_range_rejects_overflow_and_u32_truncation`. **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`): 976 passed, 0 failed, 45 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 -- rect_vb_range execute_indirect`: 4 passed, 0 failed (the new test and the three `execute_indirect` tests next to it, one of which the rebase had to be merged around) **Regression run** main (`20cf130`, clean tree, no local changes): ``` xcl-smoke v1 commit: 20cf13022f764208384c610c2ae6a3f4eed201a2 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1556 (PresentX 1556) presents per 2 s (last 3): 24 21 54 device removals: 0 crashes: 0 peak commit: 19607 MB ``` PR (`618f4c2`, clean tree, no local changes): ``` xcl-smoke v1 commit: 618f4c2d5417e9df54595583cdfc0a5a6f9f5728 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: 18702 MB ``` (The head is on `689f2db`; `main` moved to `20cf130` while the suite ran, and the main block is that commit, run right after the PR's. Both peak higher than the blocks this PR had before, 14.6 GB: several long runs of the title on this machine in between filled its caches, and its runs now commit 17–20 GB in the first minute whatever the build. I have not isolated why.) **Not tested** - a title that passes such a `first_vertex` or `stride` (the unit test calls `rect_vb_range` directly) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: audited `bind.rs`, wrote the fix and unit test, rebased onto `689f2db` (resolving the conflict with the test `main` added at the same place), ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
draw_rects computed `va as usize + first_vertex as usize * stride as usize`,
`first_vertex as usize * s + len`, and `(rects * 6 * s) as u32` with
unchecked arithmetic. Large title-supplied `first_vertex` or `stride`
values could panic in debug, wrap past the `> bytes` bounds check in
release, or silently truncate the expanded `D3D12_VERTEX_BUFFER_VIEW::SizeInBytes`.

Extract rect_vb_range() using checked_mul, checked_add, and u32::try_from,
returning false from draw_rects when any range or size check fails.

Assisted-by: OpenCode (Claude Fable 5.2)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:34 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 19:02 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head 1d751bb (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 776 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: rect_vb_range_rejects_overflow_and_u32_truncation.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as #1651.
  • In the first run, with another PR's suite running on the same machine, hle::kernelx::tests::fine_timer_makes_short_sleeps_short failed (a Sleep(1) timing check, sensitive to load). The run above was alone on the machine and is clean.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 19:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1561#issuecomment-7141518526) Full-suite run, since this PR has no test report yet. Tested exact head `1d751bb` (on its base `9e3831e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form`: **776 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `rect_vb_range_rejects_overflow_and_u32_truncation`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **777 passed, 0 failed, 41 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `heap_window_out_of_memory_falls_back_to_the_switch_form` was skipped with `--skip`. It fails on main `9e3831e` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (`XCL_HEAP_WINDOWS` unset). Reported as #1651. - In the first run, with another PR's suite running on the same machine, `hle::kernelx::tests::fine_timer_makes_short_sleeps_short` failed (a `Sleep(1)` timing check, sensitive to load). The run above was alone on the machine and is clean. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 19:32 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 19:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1561#issuecomment-7142246164) 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

@⁠b3IKK on GitHub · 2026-11-24 23:25 UTC · original

Rebased onto 689f2db (GitHub showed a conflict: main had added a test at the same place in bind.rs; both are kept, nothing else changed). Head 618f4c2: 976 passed, 0 failed, 45 ignored; smoke blocks in the description. AI use: OpenCode, Claude Fable 5.2.

**@⁠b3IKK** on GitHub · 2026-11-24 23:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1561#issuecomment-7147378880) Rebased onto `689f2db` (GitHub showed a conflict: `main` had added a test at the same place in `bind.rs`; both are kept, nothing else changed). Head `618f4c2`: 976 passed, 0 failed, 45 ignored; smoke blocks in the description. AI use: OpenCode, Claude Fable 5.2.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:48 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:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/1561#issuecomment-7183821740) 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/1561/head:github-bot/gh-1561'
git switch 'github-bot/gh-1561'

Merge

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