Skip to content

DXIL assemble: guard null/empty DXC blobs, null COM interfaces, and 32-bit IR length - #2587

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxil-assemble-dxc-blob-null-safety
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxil-assemble-dxc-blob-null-safety

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Fixes three DXC FFI safety bugs in crates/xcl/src/gpu/recomp/dxil/assemble.rs: empty/null DXC blob slice::from_raw_parts UB in errors() and assemble(), missing null COM interface pointer check in make<T>(), and silent 32-bit IR length truncation via ir.len() as u32. Part of #2413, Part of #1833, Part of #1269.

What is in it

  • crates/xcl/src/gpu/recomp/dxil/assemble.rs (blob_bytes, errors, assemble): factor blob_bytes(ptr, len) returning Ok(&[]) when len == 0 (never calling slice::from_raw_parts on null), Err("null DXC blob buffer") when ptr.is_null() && len > 0, and Ok(slice) otherwise; trim trailing \0 bytes in errors() and fall back to formatting the failed HRESULT when the error buffer is missing, empty, or whitespace-only; reject an empty validated container in assemble() with "assemble: empty DXIL container".
  • crates/xcl/src/gpu/recomp/dxil/assemble.rs (make): check if p.is_null() after DxcCreateInstance returns S_OK before calling T::from_raw(p), returning Err("DxcCreateInstance: returned null interface").
  • crates/xcl/src/gpu/recomp/dxil/assemble.rs (blob_len, assemble): validate ir.len() with u32::try_from(len) instead of truncating via ir.len() as u32 before calling IDxcUtils::CreateBlob.
  • crates/xcl/src/gpu/recomp/dxil/assemble.rs (mod tests): added 3 pure-CPU / mock-COM 0-skip unit tests (blob_bytes_and_blob_len_validate_null_empty_and_bounds, make_rejects_null_interface_and_propagates_hresult, and errors_handles_null_empty_blob_trims_nuls_and_falls_back_to_hresult) alongside preserved ir_text_assembles_signs_and_runs.

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: Windows 11 Home (build 26200), NVIDIA GeForce RTX 4060 8 GB (driver 621.14, 32-lane waves), Intel Core i5-11400F (6C/12T), 32 GB RAM, rustc 1.100.0, DXC 1.9.2609.5, --release.
  • Failing-first on unmodified 08db8020: make_rejects_null_interface_and_propagates_hresult aborted with 0xc000001d (STATUS_ILLEGAL_INSTRUCTION) inside IUnknown::from_raw(null) before the null-pointer guard was added.
  • Post-fix targeted cargo test --release -p xcl --lib -- gpu::recomp::dxil::assemble::tests:: --nocapture: 4 passed, 0 failed, 0 ignored, 0 skips on both RTX 4060 and WARP (XCL_ADAPTER=warp, XCL_WARP=1).
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture: 37 test binaries, 1432 passed, 0 failed, 47 ignored (SKIPPED GPU/host tests: 29 pre-existing on 32-lane RTX 4060 without D3D12 debug layer — 21 no wave64, 3 per-lane wave32 refused, 3 no D3D12 debug layer, 1 no heap windows, 1 cannot disable driver cache; 0 skipped in gpu::recomp::dxil::assemble::tests).

Regression run

main:

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1549 (PresentX 1549)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13985 MB

PR:

xcl-smoke v1
commit: 534deb254f8404238be1c7a89f4198cf26a65e1a
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1573)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13994 MB

Not tested

  • 64-lane AMD hardware (wave64 GPU tests skipped on 32-lane RTX 4060) and D3D12 debug-layer tests (SDK layers DLL not installed on host).
  • 4 GiB+ live CreateBlob allocation (covered via blob_len((u32::MAX as usize) + 1) unit check).

AI use

  • Google Antigravity (Gemini 4 Neon) implemented the DXC blob/COM null-safety and IR length checks, added the pure-CPU and mock-COM unit tests, ran the failing-first, post-fix, workspace, and paired 60 s smoke verifications, and drafted this PR description.

…2-bit IR length

Fix three FFI safety bugs in crates/xcl/src/gpu/recomp/dxil/assemble.rs:

1. Guard empty and null DXC blob pointers via blob_bytes() before calling
   std::slice::from_raw_parts() in errors() and assemble(), trimming trailing
   NULs, falling back to the failed HRESULT when the error buffer is empty, and
   rejecting an empty validated DXIL container.
2. Check for a null COM out-pointer in make<T>() after DxcCreateInstance
   returns S_OK before calling T::from_raw(p).
3. Check ir.len() with u32::try_from() via blob_len() instead of silently
   truncating via `ir.len() as u32` before calling IDxcUtils::CreateBlob.

Part of xcl-dev#2413
Part of xcl-dev#1833
Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
@futurepro62

futurepro62 commented Nov 26, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 534deb25 (on its base 08db802).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, 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 --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1420 passed, 0 failed, 45 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: blob_bytes_and_blob_len_validate_null_empty_and_bounds, make_rejects_null_interface_and_propagates_hresult, errors_handles_null_empty_blob_trims_nuls_and_falls_back_to_hresult.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1431 passed, 0 failed, 47 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 08db8020 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

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.

@DarkPanda69

Copy link
Copy Markdown

64-lane AMD run (listed as untested; the report above is NVIDIA): the 3 new tests pass, and nothing else changes in the GPU suite on an RX 9070 XT or an RTX 3060.

Head 534deb2 applied on main b49be18, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, card chosen with XCL_ADAPTER:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010) 708 passed, 2 failed, 6 SKIPPED 711 passed, 2 failed, 6 SKIPPED
RTX 3060 (32.0.16.1088) 710 passed, 0 failed, 24 SKIPPED 713 passed, 0 failed, 24 SKIPPED

On both cards, the only result changes against main are the new blob_bytes_and_blob_len_validate_null_empty_and_bounds, errors_handles_null_empty_blob_trims_nuls_and_falls_back_to_hresult and make_rejects_null_interface_and_propagates_hresult, all ok, with no new skips. So the wave64 GPU tests that skip on a 32-lane GPU ran with this PR on the RX 9070 XT and still pass. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on main.

Not tested: the D3D12 debug-layer tests (no d3d12SDKLayers.dll here either), Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@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

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.

4 participants