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

Open
opened 2026-11-25 18:07:29 +00:00 by ahmetbagci8 · 0 comments
ahmetbagci8 commented 2026-11-25 18:07:29 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by ahmetbagci8 on 2026-11-25T18:07:29Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6610688105 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2413). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-25T18:07:29Z. --- ### 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#2403
No description provided.