Shaders: fix DXIL validator UB on null error blobs, unchecked GetStatus, and COM/DLL handle leaks #477
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!477
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@nathanbzrr on GitHub · 2026-11-24 03:50 UTC · original
nathanbzrr:fix/shader-validator-com-soundness→main· +124 −14 · 2 files · 2 commits · openProblem
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.
@DaviTostes on GitHub · 2026-11-24 03:56 UTC · original
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.@nathanbzrr on GitHub · 2026-11-24 21:35 UTC · original
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.@Marvisak on GitHub · 2026-11-25 00:27 UTC · original · edited 2026-11-25 03:25 UTC
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
@nathanbzrr on GitHub · 2026-11-25 00:48 UTC · original
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 ok@Calvix2k on GitHub · 2026-11-25 02:30 UTC · original
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.@nathanbzrr on GitHub · 2026-11-25 03:08 UTC · original
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)@fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original
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.