Shaders: bounds-check DXBC signature table before Vec::with_capacity #1499

Closed
github-bot wants to merge 1 commit from gh-pr/1499/head into gh-pr/1499/base
Owner

@⁠b3IKK on GitHub · 2026-11-24 16:59 UTC · original
b3IKK:gpu/dxbc-signature-bounds → main · +16 −2 · 1 files · 1 commits · closed without merging

dxbc::signature() called Vec::with_capacity(count) with the raw u32 element count from an ISG1 / OSG1 / ISGN / OSGN part before verifying that first + count * size <= d.len(). A small malformed signature part claiming count = u32::MAX aborted the process on an unbounded ~206 GiB allocation instead of returning None.

This validates first + count * size <= d.len() with checked arithmetic before allocating, and uses checked additions in rd32 and psv.

What is in it

  • crates/xcl/src/gpu/dxbc.rs: bounds-check the signature table before Vec::with_capacity(count), use checked additions in rd32 and psv, and add unit test truncated_or_oversized_signature_returns_none_without_allocating.

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): 771 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib gpu::dxbc::tests: 3 passed, 0 failed

Regression run

main:

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

PR:

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

Not tested

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

AI use

  • OpenCode, Gemini 4 Neon: audited gpu/dxbc.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 16:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1499) `b3IKK:gpu/dxbc-signature-bounds` → `main` · +16 −2 · 1 files · 1 commits · closed without merging `dxbc::signature()` called `Vec::with_capacity(count)` with the raw `u32` element count from an `ISG1` / `OSG1` / `ISGN` / `OSGN` part before verifying that `first + count * size <= d.len()`. A small malformed signature part claiming `count = u32::MAX` aborted the process on an unbounded ~206 GiB allocation instead of returning `None`. This validates `first + count * size <= d.len()` with checked arithmetic before allocating, and uses checked additions in `rd32` and `psv`. **What is in it** - `crates/xcl/src/gpu/dxbc.rs`: bounds-check the signature table before `Vec::with_capacity(count)`, use checked additions in `rd32` and `psv`, and add unit test `truncated_or_oversized_signature_returns_none_without_allocating`. **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`): 771 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib gpu::dxbc::tests`: 3 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 8afc955d3385cf2d4ee0e9f0ac7377ca229f485d gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1657 (PresentX 1657) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14469 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `gpu/dxbc.rs`, wrote the fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
dxbc::signature() called `Vec::with_capacity(count)` with an untrusted
u32 count parsed from the ISG1/OSG1/ISGN/OSGN part before verifying
that `first + count * size <= d.len()`. A small malformed signature part
claiming `count = u32::MAX` aborted the process with an OOM allocation
instead of returning None.

Validate `first + count * size <= d.len()` with checked arithmetic
before allocating, and use checked additions in `rd32` and `psv`.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:44 +00:00
github-bot closed this pull request 2026-11-26 04:55:44 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original

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

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

Thanks!

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

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

Test report for 8afc955d on NVIDIA (RTX 3060 Ti): passes, and without the fix the test aborts on the allocation it guards

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 8afc955d as is (base b7aa9f3), clean tree.
  • The new test (truncated_or_oversized_signature_returns_none_without_allocating) with cargo test -p xcl --lib <name>: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 771 passed, 0 failed, 41 ignored; its base b7aa9f3 on the same machine: 770 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • 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 gpu/dxbc.rs reverted (test kept), the test process aborts with memory allocation of 206158430160 bytes failed.

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:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1499#issuecomment-7142967980) **Test report for `8afc955d` on NVIDIA (RTX 3060 Ti): passes, and without the fix the test aborts on the allocation it guards** **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 `8afc955d` as is (base `b7aa9f3`), clean tree. - The new test (`truncated_or_oversized_signature_returns_none_without_allocating`) with `cargo test -p xcl --lib <name>`: 1 passed. - `cargo test --workspace -- --test-threads=4` on the head: **771 passed, 0 failed, 41 ignored**; its base `b7aa9f3` on the same machine: 770 passed, 0 failed, 41 ignored. SKIPPED on both: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64). - 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 `gpu/dxbc.rs` reverted (test kept), the test process aborts with `memory allocation of 206158430160 bytes failed`. **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

@⁠b3IKK on GitHub · 2026-11-25 00:04 UTC · original

On #1607's group D61: #1116 came first and makes the same change in signature. I am leaving this one open for now only because #1116's PR description check currently fails, so it cannot be merged as it stands, while this one passes and was run in batches B2 / B13. If #1116's check goes green I will close this in its favour; the two extra checked_add calls here (rd32, psv) can then be a follow-up. AI use: OpenCode, Claude Fable 5.2.

**@⁠b3IKK** on GitHub · 2026-11-25 00:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/1499#issuecomment-7148099976) On #1607's group D61: #1116 came first and makes the same change in `signature`. I am leaving this one open for now only because #1116's `PR description` check currently fails, so it cannot be merged as it stands, while this one passes and was run in batches B2 / B13. If #1116's check goes green I will close this in its favour; the two extra `checked_add` calls here (`rd32`, `psv`) can then be a follow-up. AI use: OpenCode, Claude Fable 5.2.
Author
Owner

@⁠CalvyPZ on GitHub · 2026-11-25 22:45 UTC · original

This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

**@⁠CalvyPZ** on GitHub · 2026-11-25 22:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/1499#issuecomment-7176756700) This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.