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

Open
opened 2026-11-26 05:30:11 +00:00 by github-bot · 0 comments
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-25 18:07 UTC · original

Summary

Two issues in crates/xcl/src/gpu/recomp/dxc.rs:

  1. Null-pointer UB on empty DXC blobs (compile_here, lines 525-536):
let s = std::slice::from_raw_parts(b.GetBufferPointer() as *const u8, b.GetBufferSize());
...
Ok(std::slice::from_raw_parts(blob.GetBufferPointer() as *const u8, blob.GetBufferSize()).to_vec())

When GetErrorBuffer() or GetResult() returns an empty blob (GetBufferSize() == 0), DXC returns nullptr from GetBufferPointer(). Passing nullptr to std::slice::from_raw_parts is UB (and panics in debug builds).

  1. Leaked dxil.dll / dxcompiler.dll handles on failed candidate load (load, lines 320-340):
    If LoadLibraryW fails for dxcompiler.dll or GetProcAddress(h, "DxcCreateInstance") fails, signer (dxil.dll) and h are never freed with FreeLibrary. Leaving dxil.dll from a failed candidate folder loaded causes Windows to reuse that stale dxil.dll when a later candidate's dxcompiler.dll loads dxil.dll by name.

Suggested fix

  1. Guard both from_raw_parts calls with if ptr.is_null() || len == 0.
  2. Call FreeLibrary(signer) / FreeLibrary(h) on error paths in load().

Not tested

  • Read from commit 082944135cd2b96288470a595861fa608eee08dc without a new runtime test.

AI use

  • Antigravity harness (Gemini 4 Neon) audited dxc.rs and drafted this report; the author reviewed it before posting.
**@⁠ahmetbagci8** on GitHub · 2026-11-25 18:07 UTC · [original](https://github.com/xcl-dev/xcl/issues/2413) ### Summary Two issues in `crates/xcl/src/gpu/recomp/dxc.rs`: 1. **Null-pointer UB on empty DXC blobs (`compile_here`, lines 525-536):** ```rust let s = std::slice::from_raw_parts(b.GetBufferPointer() as *const u8, b.GetBufferSize()); ... Ok(std::slice::from_raw_parts(blob.GetBufferPointer() as *const u8, blob.GetBufferSize()).to_vec()) ``` When `GetErrorBuffer()` or `GetResult()` returns an empty blob (`GetBufferSize() == 0`), DXC returns `nullptr` from `GetBufferPointer()`. Passing `nullptr` to `std::slice::from_raw_parts` is UB (and panics in debug builds). 2. **Leaked `dxil.dll` / `dxcompiler.dll` handles on failed candidate load (`load`, lines 320-340):** If `LoadLibraryW` fails for `dxcompiler.dll` or `GetProcAddress(h, "DxcCreateInstance")` fails, `signer` (`dxil.dll`) and `h` are never freed with `FreeLibrary`. Leaving `dxil.dll` from a failed candidate folder loaded causes Windows to reuse that stale `dxil.dll` when a later candidate's `dxcompiler.dll` loads `dxil.dll` by name. ### Suggested fix 1. Guard both `from_raw_parts` calls with `if ptr.is_null() || len == 0`. 2. Call `FreeLibrary(signer)` / `FreeLibrary(h)` on error paths in `load()`. ### Not tested - Read from commit `082944135cd2b96288470a595861fa608eee08dc` without a new runtime test. ### AI use - Antigravity harness (Gemini 4 Neon) audited `dxc.rs` and drafted this report; the author reviewed it before posting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:30:11 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.