Skip to content

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

Closed
kotekompotek wants to merge 1 commit into
xcl-dev:mainfrom
kotekompotek:fix/dxc-empty-blob
Closed

kotekompotek wants to merge 1 commit into
xcl-dev:mainfrom
kotekompotek:fix/dxc-empty-blob

Conversation

@kotekompotek

@kotekompotek kotekompotek commented Nov 25, 2026 •

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Integrates upstream amd-dev 9f02a3b (BVH null/OOB guard), b67375b (scratch
SADDR 0x7F), 4ae5668/xcl-dev#2565 (32-bit VALU add/sub carry without i64), plus
open PRs xcl-dev#2559 (bfm/ffbh_i), xcl-dev#2557 (known_nonzero_bits folding), xcl-dev#2552
(f16-to-f32 fold), xcl-dev#2568 (integer min/max range opt), and xcl-dev#2580 (empty DXC
blob null slice).

Assisted-by: Antigravity (Gemini 4 Neon)
)

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.
@throny

throny commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@kotekompotek

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler/DXC: null-pointer UB on empty DXC blobs and leaked dxil.dll handle on failed candidate load

3 participants