D3D12-SHADER-VALIDATOR-COM-ERROR-AND-NULL-BLOB: check GetStatus, release COM refs, guard null error blobs #3010
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
3 participants
Due date
No due date set.
Reference
leonida/mandy!3010
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3010"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: D3D12-SHADER-VALIDATOR-COM-ERROR-AND-NULL-BLOB### What and why
Validator::validateind3d12/crates/leonida-shader/src/emit/validator.rshad three defects on the DXIL validator path:- theHRESULTfromIDxcOperationResult::GetStatuswas discarded, so a failed call leftstatus == 0and validation was reported as successful;- a failedIDxcValidator::Validatecould still hand back an owned result object, which was leaked on the early return;- the error blob'sGetBufferPointerresult was passed toslice::from_raw_partsunchecked (undefined behaviour for a null pointer).Every COM out-parameter is now wrapped in an RAIIComPtrimmediately,GetStatus's ownHRESULTis checked, and the error blob is read only when its pointer is non-null and its length is nonzero. The error text, NUL trimming, andrejected (...)fallback are unchanged.Seven synthetic COM-vtable unit tests cover validation failure,GetStatusfailure,GetErrorBufferfailure, a null error-blob object, a null blob pointer, a real blob message, and the success path, asserting release counts on each path.### Tested-cargo test -p leonida-shader --locked emit::validatorΓÇö 11 passed, 0 failed (7 new).-cargo clippy -p leonida-shader --locked --lib -- -D warningsΓÇö clean. (--all-targetsstill reports six pre-existing warnings in the untouchedemit/valu_tests.rs.)- Red/green: with the tests applied to the old source (via a test-only shim overValidator::validate),null_error_blob_pointer_is_never_dereferencedaborted on thefrom_raw_partsprecondition andget_error_buffer_failure_releases_both_objectsfailed on a leaked reference; with this change all seven pass.-python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/validator.rsΓÇö clean.- Independent read-only review: Gemini 4 Neon (mode review, thinking low) audited the full diff and reported no defects.GPUs tested: n/a (offline Rust unit tests; no GPU, shader input or game data involved)AI-assisted: yes ΓÇö Gemini 4 Neon (architecture direction and independent diff review).### Checklist- [x] Based on currentmainand merges cleanly (a conflicting pull request is labeledneeds rebase).- [x] One topic; follow-up work goes in a new pull request.- [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.- [x] A new translator rule is in the contract table ofdocs/design.md, with how it was confirmed. ΓÇö n/a: no translator rule changed.Verified the production success path at d77024931 with the Windows SDK 10.0.26100.0 x64 dxil.dll. I compiled a small compute shader with the matching dxc.exe (-T cs_6_0 -E main -Vd), then called Validator::load and Validator::validate from a temporary crate test. The input container had an all-zero 16-byte digest. Validation succeeded and filled the digest in place. This check exercised SDK interoperability and signing on valid input. Codex-assisted.
VERIFY-3010 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files
Verdict: MIXED. The production change is a correct root-cause fix, and its new tests are genuine discriminators — I ported the verbatim
com_testsmodule and both the base and the newvalidate_withinto a standalone Linux harness and ran them: 4 of the 7 fail on the base logic, all 7 pass on the new logic. But the whole module is#[cfg(windows)], so the crate's own suite never compiles these tests on Linux and the repository'sred_green.pyreturns "no red" here. Crate-level red→green on the real Windows target is therefore unverified; my red→green evidence comes from the faithful standalone port, not the crate's own test binary.Head
d645712a3b4fe5533d88e23ae8f08b15b482afb2, base the currentmain(origin/main8422def759cda12c89f918438eeb8d53dd5972a6), merge base2705632c561ad9e176fcc05234b66d841aa66aa9, 1 file, +361/−44:d3d12/crates/leonida-shader/src/emit/validator.rs(+361/−44)1. What it changes
It rewrites the COM call sequence in the DXIL validator's
validateso it stops leaking COM references and stops trustingGetStatus. Three defects in the base code, each fixed at the root:(a) Ignored
GetStatusHRESULT — a failed validation could be reported as success. The base read the status but threw away whetherGetStatusitself succeeded:If
GetStatusfails it need not writestatus, sostatusstays 0 and the base returnsOk(())for a validation whose outcome it never learned. The new code checks the HRESULT first:(b) COM references leaked on early-return paths. The base released
resultonly on the one path that reachedrelease(result)and releasederrorsonly insideif get_errors(...) >= 0 && !errors.is_null(); thehr < 0 || result.is_null()early return and theget_errorsfailure path leaked. The new code wraps every COM out-parameter in an RAII guard the moment it is produced, so it is released exactly once on every path:(c) Null error-blob pointer dereferenced. The base did
std::slice::from_raw_parts(ptr(errors), len(errors))with no null/zero-length check, so a null buffer pointer or a 0/usize::MAXlength is undefined behaviour. The new code guards it:It also factors the body into a free
unsafe fn validate_with(object, container)so the new tests can drive it with synthetic COM objects.2. The new test checks the property that matters
The PR adds a
com_testsmodule of 7 tests that build fake COM vtables (a fake validator, result and error blob, each counting itsReleasecalls) and callvalidate_withdirectly — nodxil.dll, no D3D12, so the logic is testable off Windows. To show they actually discriminate, I extracted the module verbatim (sed -n '353,635p'of the PR'svalidator.rs) and compiled it against both implementations in a standalone Linux harness (rustc --test --edition 2024), then ran each side:validate_failure_releases_the_returned_resultget_status_failure_is_not_reported_as_successget_error_buffer_failure_releases_both_objectsnull_error_blob_pointer_is_never_dereferencedrejection_text_comes_from_the_error_blobnull_error_blob_object_falls_back_to_the_statussuccess_releases_the_result_onceWhy each base failure is the real defect:
validate_failure_releases_the_returned_result: the base'sif hr < 0 || result.is_null() { return Err(...) }returns beforerelease(result), leaking the result reference. The newComPtrreleases it on the early return.get_status_failure_is_not_reported_as_success: the fake'sstatus_hr = -1andstatusleft 0. The base ignoresstatus_hr, seesstatus == 0, and returnsOk(()); the test asserts the error string, sounwrap_err()panics. This is defect (a).get_error_buffer_failure_releases_both_objects: the fake'sget_errorsreturns a failing HRESULT with a non-null blob. The base never enters theget_errors >= 0block, so the blob'sReleaseis never called (count 0, expected 1) — a leak. The newComPtrreleases both.null_error_blob_pointer_is_never_dereferenced: the fake returnsdata = null, len = usize::MAX. The base callsfrom_raw_parts(null, usize::MAX), which aborts on the slice UB precondition (unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null…, process exit 134 — with-Oit segfaults, exit 139). This is defect (c).The three that pass on both confirm behaviour is preserved (rejection text is trimmed of its NUL, a null error-blob object still falls back to the status string, and success releases the result once). So the suite both catches the four regressions and pins the unchanged paths.
3. What the tests do here
python3 -I scripts/red_green.py 3010 --crate leonida-shader --work-dir .../rg-3010(verdictno red, exit 1):origin/main+ this PR's tests only)origin/main+ this PR merged)origin/mainon its ownd645712aon its ownNothing failed on either side and nothing moved red→green, because the entire changed file is Windows-gated —
emit/mod.rshas#[cfg(windows)] pub mod validator;. The 7 newcom_teststests are inside that module, so on Linux they are not compiled and not run; the crate's Linux suite is identical with and without the PR. The table above is a true statement about Linux, but the crate-level red→green for these tests simply cannot happen here.The red→green evidence is the standalone harness in section 2: it embeds the verbatim
com_testsbody and verbatim base/newvalidate_with(ported fromgit show 2705632c:…validator.rsand the PR diff), so the logic is the PR's own even though the surrounding Windows-gated module is elided.4. Any failure I saw, and why it is not this pull request
No failure attributable to this pull request. The green side builds and all 252 Linux tests pass with the PR merged, identical to base. The only red anywhere in my runs was the intended red: the base logic failing the new tests inside my harness (section 2), which is the PR doing its job. I gave this run its own
--work-dir, so thesource_hash_testsshared-target-dir trap never appeared.5. What I did not check
dxil.dll/ D3D12 validator. All 7 new tests use synthetic COM fakes; nothing here exercised the real Windows validator. The real-DLL path (Validator::load, theBlobQueryInterface, the actualIDxcValidator::Validateround-trip) is untouched by the diff and untested here.validator.rsis#[cfg(windows)], so no Linux build type-checks it. A syntax or type error in the rewrittenvalidate_withwould not surface on Linux. My harness compiled a copy of the logic, which is strong evidence the logic is right but is not the crate compiling.red_green.pycannot construct a meaningful red/green for a Windows-only module from Linux; the crate-levelred then greenverdict was not obtained.run_gpu_tests.py) or Wine (run_wine_tests.py) suites. None run; not applicable to this COM-plumbing change.Net: against the repository's own rules this scores well — it fixes each defect at the root (RAII ownership, check the HRESULT, validate the pointer) rather than stacking workarounds, keeps
validate_withsmall and readable, and ships a new test that fails onmainand passes with the PR (demonstrated in the port). The one honest gap is that none of it compiles on Linux, so I proved the tests discriminate in a faithful standalone harness, not in the crate.This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
Ran natively on Windows 11, head
d645712a3merged into currentmain(d0bf821fa, clean merge), pinned toolchain, MSVC target. The Linux report above could not compilevalidator.rsbecause the module is#[cfg(windows)], so it left two things open. This covers both, the crate building and running these tests on Windows and a crate-level red/green. It also runs both versions against the SDKdxil.dllon rejection paths. The success path with the real DLL is already covered above.Suites on the merge
emit::validator(7 newcom_tests+ 4 existing)leonida-shaderlib--all-targetsvalidator.rs(7 warnings elsewhere in the crate)Red/green in the crate on Windows
For the red side I kept the PR's
com_testsmodule verbatim onmain. A test-onlyvalidate_withbuilds aValidatoraround the fake object, calls main'svalidate, and forgets it. Each test ran in its own process with--exact, because the null-pointer test aborts the binary.validate_failure_releases_the_returned_resultget_status_failure_is_not_reported_as_successunwrap_erronOkget_error_buffer_failure_releases_both_objectsnull_error_blob_pointer_is_never_dereferencedslice::from_raw_partsprecondition (exit 127)rejection_text_comes_from_the_error_blobnull_error_blob_object_falls_back_to_the_statussuccess_releases_the_result_onceThat is the same 4 red, 3 green split as the Linux port, now from the crate's own test binary.
Extra fake-COM cases on the PR
ValidateE_FAIL, result nullValidate failed: 0x80004005ValidateS_OK, result nullValidate failed: 0x0ValidateE_FAIL, result non-nullValidate failed: 0x80004005GetStatusfails and writes a negative statusGetStatus failed: 0x8000ffffS_FALSE(1)Ok(())rejected (0xffffffff)rejected (0xffffffff)bad �� dxil(lossy)rejected (0xffffffff)GetErrorBufferfails, blob nullrejected (0xffffffff)GetErrorBuffer)Ok(()),GetErrorBuffercalled 0 timesEvery object handed out is released exactly once, and nothing is released that was never handed out. The only odd output is
Validate failed: 0x0whenValidatereturns success with no result object. It is correct to fail, but the message shows a success code.Real
dxil.dll(SDK 10.0.26100), main and PRThe input is a small compute shader compiled with the SDK
dxc.exeusing-Vd, then altered.Ok, digest filledOk, digest filledPSV0part flippedErr("error: DXIL container mismatch for 'PSVRuntimeInfo' ...")Validate failed: 0x80004005Validate failed: 0x8007000eErr("Validation failed.")Calling
Validatedirectly on the two flipped-byte inputs gave a failing HRESULT and a null result object both times. On this DLL, then, thehr < 0path does not hand back a result, and the leak fixed there only matters for other DLLs or the fakes. Over 40,000 rejected validations (PSV0 mismatch, which goes throughGetErrorBuffer), private bytes stopped growing after the first 20,000 on both sides (PR +308, +36, +0, +0 KiB per 10,000, main +300, +44, +0, −20 KiB). So the normal rejection path did not leak before and does not leak now.The empty-slice crash happens before this PR and is not changed by it. An empty
&mut [u8]passes a dangling non-null pointer with length 0, and the DLL reads it. A length check before callingValidatewould turn that into anErr. Production callers pass translated containers, so this probably never happens in practice.Not checked: other
dxil.dllversions; a real DLL that returns a non-null result alongside a failing HRESULT; the in-game run requested above (this change is on the shader translation side and I did not launch the game).GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).
Triage of head
d645712a3(merge base2705632c5, 309 commits behind;git merge-treeagainst currentmain45dc41f95: no conflicts).1 file:
d3d12/crates/leonida-shader/src/emit/validator.rs(+361/-44).CI green on the head (6 checks, including
d3d12 (windows-latest)).Existing verification: @andrew-ai verified the success path with a real
dxil.dll; @imShangLi's Linux port of the tests was MIXED only becausevalidator.rsis#[cfg(windows)]; @Kal0s-design then built and ran the crate natively on this head merged ontod0bf821fa, covering both open points.This check: Read the diff:
GetStatus'sHRESULTis now checked (a failed call no longer reads asstatus == 0, success), a failedValidatereleases its result, and a null error blob is handled. These are real correctness fixes on the validator path. The +361 lines are mostly a mock-COM test module; it is long for the fix, but it is what makes the failure paths testable without a brokendxil.dll.I did not build it: the crate is Windows-only (or the C++ runtime's Windows build), so no red/green was run here.
Verdict: ready (verified natively on Windows on this head).
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
Windows native unit verification (
VERIFY-3010-WIN) — PASS WITH NOTE on headd645712a3b4fe5533d88e23ae8f08b15b482afb2(merged cleanly onto80910637f, Ryzen 9 5900X / Windows 11 / MSVC):scripts/check_no_game_data.pyon changed files): PASS.80910637f):cargo test -p leonida-shader --locked -- validator:: --test-threads=1(and with--features diagnostics) exited101(E0425,cannot find function validate_with in this scopeintroduced by this PR).cargo test -p leonida-shader --locked -- validator:: --test-threads=1: 11 passed.cargo test -p leonida-shader --locked --features diagnostics -- validator:: --test-threads=1: 11 passed.HRESULTfailures, reference release, and null error blobs; the base overlay failed at compile time onvalidate_withbefore those assertions ran.(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head
d645712a3b4fe5533d88e23ae8f08b15b482afb2(in addition to the Windows unit verification posted above).git merge --no-ffontomainb41763227(diagnostics,dlss,mimalloc,exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit0).14PRs):#3200d1a91afd1,#319880a627bb1,#319193b47ac9d,#3189c182fc392,#3176ae0075d9a,#3168337388052,#31641065952da,#3146ebc0253ff,#312464600ef0c,#3069311d33a40,#30318df1bfce7,#3029e49404808,#3054ff53fd8b9,#3010d645712a3.610.88, Series X profile,2560x1440,-NoFrameGen,scripts/game-gate.ps1(301.3 sin world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (GATE CONTROL moved=2.51 m,max_from_ctrl=5,053.9 m).PASS(0device lost,0crashes,0warnings,0missed pipeline waits,20.10 FPSmedian vs19.13 FPSmainb41763227baseline, clean exit0x00000000).(AI-assisted verification:
gemini-4-neon+gpt-6.2-astra.)VERIFY-3010 — Windows nativo: las once pruebas del validador pasan, y el control muerde
(this PR)2705632c5(behindmainb41763227)main—merge-treeclean,git merge --no-ffcleanRan
Negative control (synthetic — the tests ship with the change, in the same file): I replaced the numeric sort with a lexicographic one (
.max_by(|a, b| a.cmp(b))), rebuilt and ran:The test bites. A lexicographic order puts
10.0.19041before9.0.…— the exact confusion the helper exists for.What the change is, from the diff: a
ComPtrthat releases its reference exactly once even on an early return (the leak path),validate_withreading its outcome from the COM result instead of assuming success, the error from a missingdxil.dllno longer carrying a trailing NUL, andsdk_version_keysorting Windows-Kits versions numerically (dot-separated parts asu64) with the path as the tie-break.What I could not test
dxil.dll/dxcompiler.dlland a shader the validator rejects; thecom_testsbuild synthetic COM objects with a fake vtable instead.Windows Kitslayout:sdk_version_keyis driven with paths the test invents; the ordering overC:\Program Files (x86)\Windows Kits\10\bin\*was not walked here.Written with an AI assistant.
Bundle gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): #3303
2892951f4, #3136fd16493ac, #30103ca5765acand #3005b3a1a8f57(the current heads) merged together intomain04a838fc4without conflict, diag profile withdiagnostics,dlss,mimalloc, msvc target. These four were judged to have no effect on the picture, so they share one run. Reference:main04a838fc4built the same way, run the same day with the same frame-timing capture on. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.main(-0.6, inside the run-to-run spread of this recipe); median frame 29.27 ms, p99 48.8 against 48.9 ms. From 210 to 300 s the 30 s slices are the same as the reference (34.4-35.0 against 34.5-34.7). The 150-210 s slices are lower: a slower climb, plus a short CPU burst from a monitoring query on this PC at 173 s.mainrun; none after 150 s.Verdict: PASS, no cost, for the four PRs together.
GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).
ab6dab7cfinto #3010 (tree tested by local CI) c0033cf132Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it, and it is part of enlighted's G1 pack, which passed a 300 s run on an RTX 3090: no cost, 0 lost, 0 crash, 0 ERROR.
Local CI (normal mode) on head
3ca5765acmerged into mainab6dab7cf: PASS.make_game.py --help.leonida,leonida-gpu,leonida-hleandleonida-shader, 841 s.The forge refused the merge while the head was behind main.
main(ab6dab7cf) was merged into the head asc0033cf13, which has the same tree the CI tested. Merged as27118932e.