DXC: an empty blob's null buffer is an empty slice, not UB (#2413) #2580

Closed
github-bot wants to merge 1 commit from github-bot/gh-2580 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:53 UTC · original
kotekompotek:fix/dxc-empty-blob → main · +22 −2 · 1 files · 1 commits · closed without merging

Fixes #2413 (the empty-blob half; the candidate-load handle leak is a separate PR).

DXC results are read out of IDxcBlobs with slice::from_raw_parts(ptr, len) (output(), shared by compile_whole, compile_linked and disassemble). An empty IDxcBlob reports a null GetBufferPointer, and from_raw_parts on a null pointer is UB even at length 0 – debug builds abort on the non-null precondition, so an empty error buffer would panic inside the error-reporting path itself (and an empty result blob on the success path).

What is in it

  • gpu/recomp/dxc.rs: a blob_bytes(ptr, len) helper maps a null pointer to an empty slice; both reads (the GetErrorBuffer text and the GetResult DXIL) go through it.
  • blob_bytes_tests: a_null_blob_buffer_is_an_empty_slice covers the null-pointer and ordinary-buffer cases. (The same from_raw_parts(blob…) shape exists in a few other files – mentioned, not changed: this PR is scoped to the DXC compile path the issue names.)

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce GTX 1050 (driver supports up to SM 6.5, no mesh shaders), DXC 1.8.2502.11 (10.0.26100.0), rustc 1.98.1 stable-x86_64-pc-windows-msvc; debug tests, release smoke builds
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1421 passed, 3 failed, 46 ignored (SKIPPED GPU tests: 355 – this adapter has no SM 6.6 / mesh shaders); run on c7eb111, the same diff before the branch was rebased onto b49be183 to resolve a collision with the new DXC linking code
  • on the pushed head 750e9d30: cargo test -p xcl --lib: 1303 passed, 3 failed, 27 ignored (4 timing-sensitive tests flaked under parallel release builds; all 4 passed in a targeted rerun)
  • the three lib failures are environmental on this machine, unrelated to the change: gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark (driver refuses a sparse heap op, HRESULT 0x80070057), stale_blob_cannot_bypass_the_offline_pipeline_cap and split_compute_program_prebuilds_and_caches_chain_pieces (both build/dispatch cs_6_6, which this SM 6.5 adapter cannot run)
  • a_null_blob_buffer_is_an_empty_slice passes; the pre-fix shape (from_raw_parts on the raw pointer) cannot be exercised through it – the UB is on the DXC edge case itself

Regression run

main:

xcl-smoke v1
commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 903 MB

PR:

xcl-smoke v1
commit: 750e9d3039d27edf99dbebd96ec5cff5c38444a3
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 901 MB

Not tested

  • The only available title cannot reach its own code on this adapter: ~2 s into its init it raises a breakpoint the same way on main and on this PR. The blocks above end it through XCL_RUN_SECONDS=0 before that point – they cover host boot, game loading and shutdown, no frames, no shaders.
  • An actual empty error/result blob from DXC in a live compile – the guard is verified at the blob_bytes unit level; DXC blobs cannot be stubbed without a COM double.
  • D3D12 debug layer; other GPU vendors.

AI use

  • Devin (SWE-2 High): verified the issue against the code, the blob_bytes helper, the unit test, the test suite, both smoke runs and this PR.
**@⁠kotekompotek** on GitHub · 2026-11-25 23:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2580) `kotekompotek:fix/dxc-empty-blob` → `main` · +22 −2 · 1 files · 1 commits · closed without merging Fixes #2413 (the empty-blob half; the candidate-load handle leak is a separate PR). DXC results are read out of `IDxcBlob`s with `slice::from_raw_parts(ptr, len)` (`output()`, shared by `compile_whole`, `compile_linked` and `disassemble`). An empty `IDxcBlob` reports a null `GetBufferPointer`, and `from_raw_parts` on a null pointer is UB even at length 0 – debug builds abort on the non-null precondition, so an empty error buffer would panic inside the error-reporting path itself (and an empty result blob on the success path). **What is in it** - `gpu/recomp/dxc.rs`: a `blob_bytes(ptr, len)` helper maps a null pointer to an empty slice; both reads (the `GetErrorBuffer` text and the `GetResult` DXIL) go through it. - `blob_bytes_tests`: `a_null_blob_buffer_is_an_empty_slice` covers the null-pointer and ordinary-buffer cases. (The same `from_raw_parts(blob…)` shape exists in a few other files – mentioned, not changed: this PR is scoped to the DXC compile path the issue names.) **Tested** - hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce GTX 1050 (driver supports up to SM 6.5, no mesh shaders), DXC 1.8.2502.11 (10.0.26100.0), rustc 1.98.1 stable-x86_64-pc-windows-msvc; debug tests, release smoke builds - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1421 passed, 3 failed, 46 ignored (SKIPPED GPU tests: 355 – this adapter has no SM 6.6 / mesh shaders); run on `c7eb111`, the same diff before the branch was rebased onto `b49be183` to resolve a collision with the new DXC linking code - on the pushed head `750e9d30`: `cargo test -p xcl --lib`: 1303 passed, 3 failed, 27 ignored (4 timing-sensitive tests flaked under parallel release builds; all 4 passed in a targeted rerun) - the three lib failures are environmental on this machine, unrelated to the change: `gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark` (driver refuses a sparse heap op, HRESULT 0x80070057), `stale_blob_cannot_bypass_the_offline_pipeline_cap` and `split_compute_program_prebuilds_and_caches_chain_pieces` (both build/dispatch cs_6_6, which this SM 6.5 adapter cannot run) - `a_null_blob_buffer_is_an_empty_slice` passes; the pre-fix shape (`from_raw_parts` on the raw pointer) cannot be exercised through it – the UB is on the DXC edge case itself **Regression run** main: ``` xcl-smoke v1 commit: e1d84b7d9153f86a97d2ec5d209d196046fc0bea gpu: NVIDIA GeForce GTX 1050 title: 9cc6a39e seconds: 0 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 903 MB ``` PR: ``` xcl-smoke v1 commit: 750e9d3039d27edf99dbebd96ec5cff5c38444a3 gpu: NVIDIA GeForce GTX 1050 title: 9cc6a39e seconds: 0 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 901 MB ``` **Not tested** - The only available title cannot reach its own code on this adapter: ~2 s into its init it raises a breakpoint the same way on main and on this PR. The blocks above end it through `XCL_RUN_SECONDS=0` before that point – they cover host boot, game loading and shutdown, no frames, no shaders. - An actual empty error/result blob from DXC in a live compile – the guard is verified at the `blob_bytes` unit level; DXC blobs cannot be stubbed without a COM double. - D3D12 debug layer; other GPU vendors. **AI use** - Devin (SWE-2 High): verified the issue against the code, the `blob_bytes` helper, the unit test, the test suite, both smoke runs and this PR.
compile_here reads IDxcBlob contents with slice::from_raw_parts(ptr, len);
an empty IDxcBlob reports a null GetBufferPointer, and from_raw_parts on a
null pointer is UB even at length 0 (debug builds abort on it) – an empty
error buffer would panic inside the error-reporting path itself. blob_bytes
maps a null pointer to an empty slice at both the error-buffer and result
reads.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:34:20 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 00:08 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 00:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/2580#issuecomment-7178432329) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 26 ignored. Thanks! — Devin
Author
Owner

@⁠throny on GitHub · 2026-11-26 01:10 UTC · original

Two contributors checked independently and found that this PR makes the same change as #2441 (for #2413): #1607, group D123. They suggest keeping #2441. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-26 01:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2580#issuecomment-7179503182) <!-- xcl-1607-hint:D123 --> Two contributors checked independently and found that this PR makes the same change as #2441 (for #2413): #1607, group D123. They suggest keeping #2441. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
github-bot closed this pull request 2026-11-26 08:47:11 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 08:42 UTC · original

Closing per the D123 dedupe in #1607 — this makes the same fix as #2441 (both return an empty slice for an empty blob's null buffer pointer instead of the UB from_raw_parts). #2441's helper is the nicer shape anyway: it ties the slice lifetime to the &IDxcBlob borrow and also guards a zero size. One data point for whoever lands it: #2441 currently conflicts with main, this head is mergeable and was verified on an RTX 3060 Ti — reopen if the other stalls.

**@⁠kotekompotek** on GitHub · 2026-11-26 08:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/2580#issuecomment-7186916358) Closing per the D123 dedupe in #1607 — this makes the same fix as #2441 (both return an empty slice for an empty blob's null buffer pointer instead of the UB `from_raw_parts`). #2441's helper is the nicer shape anyway: it ties the slice lifetime to the `&IDxcBlob` borrow and also guards a zero size. One data point for whoever lands it: #2441 currently conflicts with `main`, this head is mergeable and was verified on an RTX 3060 Ti — reopen if the other stalls.

Pull request closed

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