Shaders: fix DXIL validator UB on null error blobs, unchecked GetStatus, and COM/DLL handle leaks #477
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/477"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T03:50:25Z.
Problem
Validatorincrates/victory-shader/src/emit/validator.rshad four COM/FFI soundness and resource management bugs:IDxcOperationResult::GetStatusreturnedHRESULTwas ignored; ifGetStatusfailed,statusremained0(S_OK) andvalidate()falsely returnedOk(()).std::slice::from_raw_parts(ptr(errors), len(errors))was called without checking!p.is_null() && n > 0, which is UB (and panics in debug builds) when an emptyIDxcBlobreturns a null buffer pointer.IDxcValidator::Validatereturnedhr < 0with a non-nullIDxcOperationResult,resultwas leaked withoutRelease().LoadLibraryW'sHMODULEwas leaked onGetProcAddressfailure,DxcCreateInstancefailure, andValidator::drop(), and the missing-DLL error included the trailing\0fromname.What changed
module: HMODULEonValidator(null for non-DLL/mock instances); stripped the trailing NUL when formattingcannot load ...; calledFreeLibrary(module)onGetProcAddress/DxcCreateInstanceerrors; and inDrop::dropreleasedself.objectbefore callingFreeLibrary(self.module).Validator::validate: releasedresultwhenValidatefails (releasealready null-checks), checked theHRESULTreturned byGetStatus, and guardedstd::slice::from_raw_partson!p.is_null() && n > 0.emit::validator::tests::null_error_blob_falls_back_without_ub) reusingBlob/BLOB_VTABLEto exercise null/empty error blobs withoutdxil.dll.Tests (head
79c27a9)rustfmt --edition 2024 --check crates/victory-shader/src/emit/validator.rs: passed.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: passed.cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passed.cargo test -p victory-shader --locked -- --test-threads=1: 70 passed, 0 failed, 0 ignored (unit tests, includingemit::validator::tests::null_error_blob_falls_back_without_ubandemit::tests::constant_color_validates); 0 doc-tests.cargo xtask policy:asset policy: 151 files ok.No game files. AI-assisted; reviewed and verified with the tests above.
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:56:02Z.
Verified
bd59ba3on Arch Linux x86_64 (rustc 1.98.1):cargo test -p victory-shader56 passed, 0 failed, 0 ignored.Caveat: the validator is Windows-only, so the Linux suite does not exercise the null error blobs,
GetStatusor the COM/DLL handle paths this PR changes. Under Wine 11.22 withoutdxil.dll, the same tests skip validation, so this needs a machine with the validator (VICTORY_DXIL) to be meaningful.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:28:24Z.
Review: APPROVED
Tested
bd59ba3on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=173 passed, including the new mock-blob validator tests.cargo clippy -p victory-shader --all-targetsis clean.victory translate --validate --pipelineson the local title executable still validates 12 of 12 through the real dxil.dll.GetStatus's HRESULT closes a real false-OK: a failed status call used to leavestatus == 0and report the shader valid.from_raw_partsis only called with a non-null pointer and a non-zero length. Theresultleak on a failedValidate, and theHMODULEleaks on every early return and inDrop, are all closed.FreeLibraryinDropis reference-counted, so severalValidators sharing dxil.dll stay safe.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:35:43Z.
Review: COMMENTED
Static review only —
emit/validator.rsis Windows-only (windows_sys), so nothing here compiles or runs on macOS; the macOS shader suite (96 passed) just proves no unrelated regression.The hygiene fixes look correct:
LoadLibraryWfailure message now trims the trailing NUL (name[..name.len() - 1]) instead of leaking it into the error string.GetProcAddressfailure nowFreeLibrarys the module (previously leaked).DxcCreateInstancefailure releases the object and frees the module.Validatefailure releasesresultwhen non-null;GetStatusHRESULT is now checked andresultreleased on failure.from_raw_parts— exactly the null-error-blob crash.release()already null-checks, so the movedrelease(errors)is safe.Dropreleases the COM object beforeFreeLibrary— correct order, since the object's vtable lives in the DLL.One question:
Validatornow storesmodule: HMODULEunconditionally, butValidator::load/default_pathpaths that don't load from a DLL (if any) must leave it null — theDropguard!self.module.is_null()covers that. Please confirm there's no constructor path that forgets to set it.Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T21:35:33Z.
Thanks @catminou4 for the review!
Confirming from
crates/victory-shader/src/emit/validator.rs:Validator::objectandValidator::moduleare private fields onValidator.Validator::loadis the sole production constructor: it only constructsOk(Validator { object, module })afterLoadLibraryWsucceeds with a non-nullHMODULEandDxcCreateInstancesucceeds (freeingmodule/ releasingobjecton every early error path).Validator { object, module }literals are the three mock tests under#[cfg(test)] mod tests, all of which explicitly setmodule: std::ptr::null_mut().Leaving commit
bd59ba3unchanged so Bundle#1511stays on the verified head.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:27:31Z.
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/validator.rs:Validator::validatenow checks theGetStatusHRESULT;resultanderrorson every path;Validator::loadfreesdxil.dllon each early error;Dropreleases the object beforeFreeLibrary;null_error_blob_falls_back_without_ubcovers the null and empty blob shapes.The new head also adds
Win32_Foundationto victory-shader'swindows-sysfeatures. That is a feature flag of a crate the package already uses, andCargo.lockis untouched. CI passes.On your reply: the explicit
Win32_Foundationfeature is what the earlier note asked for. Nothing else is needed from this review.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T00:48:48Z.
Trimmed in
79c27a9(fix/shader-validator-com-soundness—1 file changed, 123 insertions(+), 13 deletions(-)vs merge based2a4bae):if !result.is_null()guard beforerelease(result)inValidator::validate.FreeLibraryprobe test (load_errors_strip_nul_and_free_module) and the ~300+ lines of mock COM vtable scaffolding, leaving one small test (emit::validator::tests::null_error_blob_falls_back_without_ub) that reusesBlob/BLOB_VTABLE.Verified on
79c27a9(Windows x86_64 MSVC):rustfmt --edition 2024 --check crates/victory-shader/src/emit/validator.rs: passedcargo clippy -p victory-shader --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader --locked -- --test-threads=1: 70 passed, 0 failed, 0 ignored (0 doc-tests)cargo xtask policy:asset policy: 151 files okImported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T02:30:42Z.
Independent verification on Windows 10 19045 (RX 7800 XT host, not relevant to this change):
558aa9a+ the "skip the GPU suites a device cannot run" patch from #1991 (this machine reports SM 6.5, so the probe suites would otherwise fail for an unrelated reason): 248 passed, 0 failed, 3 ignored forcargo test -p victory-shader --lib.emit::validator::tests::null_error_blob_falls_back_without_ubpasses on the unpatched head too (1 passed), and the SDKdxil.dllhere is the 1.7 one from 10.0.26100, so the null-blob path is exercised with the same engine your report used.No objection to the diff from a COM/HRESULT standpoint:
GetStatusfailure is now an error instead of a silentOk(()), the slice is built only for a non-null, non-empty blob, and the operation result is released on the error path.Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T03:08:31Z.
Added
Win32_Foundationexplicitly towindows-sysfeatures incrates/victory-shader/Cargo.toml(head249de66, without touchingCargo.lock), per the triage note.Re-verified on
249de66(Windows MSVC,VICTORY_DXILSDK10.0.26100.0):cargo run -p xtask -- policy --staged:asset policy: 1 files okcargo clippy --workspace --all-targets -- -D warnings&--all-features: cleancargo test -p victory-shader --locked: 248 passed, 0 failed, 3 ignored (includingemit::validator::tests::null_error_blob_falls_back_without_ub)Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:08:22Z.
Code review and Windows 11 (
dxil.dll) verification at head249de665216emerged cleanly ontomain(63bcca43c6a0):crates/victory-shader/src/emit/validator.rs:156-247):Validator::loadreleases acquired COM objects andHMODULEonGetProcAddress/DxcCreateInstancefailures;Dropreleasesself.objectstrictly before callingFreeLibrary(self.module), keeping OS module refcounts balanced across multi-threaded validator creation/drop.validate()checksValidate,result.is_null(), andGetStatus, releases bothresultanderrorson every exit path, and checks!p.is_null() && n > 0beforeslice::from_raw_parts, falling back toformat!("rejected ({status:#x})")on empty/null error blobs.dxil.dll10.0.26100.0, NVIDIA RTX 5090 + WARP, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warningsvalidator:: emit::host::: 2/2 passed on both RTX 5090 and WARP (includingnull_error_blob_falls_back_without_ub); livedxil.dllvalidation (v_fract_f32_never_returns_one) passed on both RTX 5090 and WARP.LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.