Repository navigation
startup: refuse null and unknown handles in XDspDeactivate and XDspDisconnect - #2261
Merged
R0Y00 merged 1 commit intoNov 25, 2026
Merged
Conversation
tedin7
reviewed
Nov 25, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
Review of head a1b55da1d4e60ea67601b0a0cb8160ea99be2402 (comment only).
Scope: src/startup_stubs/chad.cpp, tests/startup_chad_check.cpp, docs/startup-runtime.md (3 files, +41/-6). Mergeable, title neutral, body starts with Part of #1887.
Commands run locally:
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: 18 files, 429 links OKpython3 tests/bidi_controls_check.py: 1544 files, no bidi controlspython3 x2w_pipe.py win2025 2261 --targets startup_chad_check,startup_stub_chad --regex startup_chad --skip-release: build OK,startup_chad_check1/1 passed (Win2025, MSVC 14.44, dev preset)- Mutation: in
release_handle()(chad.cpp:40) replaced!= &connectionwith== nullptr, ran the same Win2025 command with--patch:startup_chad_checkFAILED withFAIL: XDspDeactivate(unknown handle) -> E_INVALIDARGandFAIL: XDspDisconnect(unknown handle) -> E_INVALIDARG. The new tests kill it. Worktree reverted afterwards. - CI at review time: Linux Python checks pass; the two Windows jobs were still pending. I did not run the
/O2or release configs.
Findings:
- P1: none.
- P2: none.
- Nit (chad.cpp:40):
&connectionis a static, so it is "known" even beforeXDspConnectWithMaximumStreamLimitpublished it, and after a later disconnect.XDspSubmitCommand(line 114) uses the same rule, so this is consistent and fine for the stand-in. A one-line comment saying that the handle is never un-published would remove the doubt. - Nit (tests): the new log assertion covers handle
0x0only. Unknown-handle log text is exercised only through the mutation run above. Optional.
What I checked and found correct:
accept()still runs first, so the strict trap path and the first-six-callsx2w-audiorecord are unchanged.- Known handle still returns 0. Null and
handle+4returnE_INVALIDARG(0x80070057), matching the #1907 submit convention. - The "failed activation cleared the stream out-pointer, then caller deactivates it" case is covered and refused.
AI-assisted; commands listed were executed locally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1887.
Change
XDspDeactivateandXDspDisconnectin thechad.dllstand-in returned 0 for any handle withX2W_AUDIO_PERMISSIVE=1, including a null handle (the row "0 for any handle" in #1887). They now refuse a null or unknown handle withE_INVALIDARGand return 0 only for the handleXDspConnectWithMaximumStreamLimitpublished, the same known-handle ruleXDspSubmitCommanduses since #1907.Neither export writes anything back to the caller: the stand-in reads only the first argument, the handle, so there is no output to clear and the change is the handle rule alone. The two reference pages are behind the developer program, so the handle-only signatures are the stand-in's assumption. Microsoft's error code list has no XDSP code for an invalid handle, so the refusal uses
E_INVALIDARG, as #1907 does for submit.XDSP_E_NOT_ALL_HANDLES_DEACTIVATEDcannot arise: activation never publishes a stream.src/startup_stubs/chad.cpp:release_handle()keeps the existingaccept()call first, so the strict trap path and the first-six-callsx2w-audiorecord are unchanged, then checks the handle and logs-> E_INVALIDARG (unknown handle)or-> 0;XDspActivate,XDspSubmitCommandandXDspConnectWithMaximumStreamLimitare unchanged, so runtime: validate chad permissive out-handle and add lifecycle checks #1871's out-handle checks and startup: fail XDspActivate and XDspSubmitCommand instead of succeeding without outputs #1907's failure paths stand.docs/startup-runtime.md: one sentence added to theX2W_AUDIO_PERMISSIVE=1row of the switches table.No change to the permissive switch, to
xapu.dllorAcpHal.dll, or to the counters in #2107. The 16-byte second argument ofXApuConnectis the next PR under the same reservation.The stop reported in #1887 after #2242 has
xapu.dllon the stack; this PR touches onlychad.dlland does not address it. I did not run an application.Verification
Base
mainat 540a961 (includes #2242). Windows 11 build 26200, MSVC 19.44.35230 x64, CMake presetsreleaseanddev.The audio-side startup tests, Release and Debug, with the stand-ins and fixtures they need built first:
tests/startup_chad_check.cppkeeps the two known-handle assertions for these exports (now labelled as such) and adds the refusal cases:XDspDeactivate(null handle)E_INVALIDARGXDspDeactivate(unknown handle)E_INVALIDARGXDspDisconnect(null handle)E_INVALIDARGXDspDisconnect(unknown handle)E_INVALIDARGXDspActivateclearedXDspDeactivate(known handle),XDspDisconnect(known handle)XDspDeactivate handle=0x0 -> E_INVALIDARGandXDspDisconnect handle=0x0 -> E_INVALIDARGpresentThe strict trap children for both exports (
0xE2570202,0xE2570203) are unchanged and pass.Evidence and follow-up
Fail-first: the new test against the
chad.cpponmain(Release) reports 6 failures, the four refusals, the synthetic caller and the log line.Negative controls, each rebuilt into
chad.dll(timestamp checked) and reverted:XDspDeactivateback toreturn accept(...)(the old behaviour)XDspDisconnectback toreturn accept(...)No new fixture: the existing source-built
startup_chad_checkgains the cases above. Not run: theprpreset smoke list (it does not includestartup_chad_check), Wine, and any application input. Not established: what a real caller passes to these two exports, or audible output. The stand-in keeps no state: as with submit, the known handle is the one connect published (there is no stream), and releasing it twice still returns 0.Checklist
AI-assisted.