Repository navigation
Conversation
…dows does (SILENT-AUDIO-HOST-ANSWERS) Measured against the host's default render endpoint on Windows 11, the same calls on each side: - A malformed WAVEFORMATEX (no channels, rate or sample size, a block or byte rate that does not follow from them, an extensible header without room for its extension) is E_INVALIDARG in Initialize and IsFormatSupported; the shim said AUDCLNT_E_UNSUPPORTED_FORMAT and took a wrong nAvgBytesPerSec as a valid format. An initialized client answers AUDCLNT_E_ALREADY_INITIALIZED before it looks at the format. - GetService(IAudioCaptureClient) is AUDCLNT_E_WRONG_ENDPOINT_TYPE, not E_NOINTERFACE. - Reset is S_OK when there was nothing to reset; the shim said S_FALSE. - IAudioRenderClient::ReleaseBuffer takes AUDCLNT_BUFFERFLAGS_SILENT and bit 31 only; any other flag is E_INVALIDARG, checked before the size, and the packet stays pending. The shim ignored the flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2387 (SILENT-AUDIO-FORMAT-AND-FLAGS-ANSWERS). This is a WASAPI shim and its test, both Windows-only: I could not build or run silent_audio_test here, so this review is a static one plus an extracted-function harness. Everything below that I say I ran, I ran.
Tested head d38ef5384 against main bdbc7e923 (git merge-tree clean; branch 10 commits behind).
Environment: Apple M3 Pro, arm64, macOS 27.2.1, Apple clang 21.0.0, CPython 3.15.2.
Why the test does not run here
silent_audio_test is registered in the WIN32-only part of runtime/CMakeLists.txt (MSVC flags, /OPT:NOREF), and runtime/shims/silent_audio.cpp includes <windows.h>, <mmdeviceapi.h>, <audioclient.h> and <spatialaudioclient.h>; the repository vendors none of them. There is no MSVC or Wine on this machine, so the new check() calls and the malformed-format loop are unexecuted here. The four behaviours the PR adds are all described as measured on Windows 11; I have no Windows host and cannot confirm the measurements themselves.
What I did run: the new classification, extracted verbatim
I copied malformed_format (and valid_format for the "before" answer) into a small C++ harness and fed it the six shapes the new test builds, plus realistic formats:
PCM 16 stereo 48k not malformed
PCM 24 stereo 48k not malformed
PCM 8 mono 22050 not malformed
float32 8ch 48k not malformed
extensible, cbSize 22 not malformed (32-bit container)
extensible, cbSize 0 malformed
and for the test's six cases, main's path vs the PR's:
no channels main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG
no rate main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG
no sample size main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG
block align 3 main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG
byte rate 1 main S_OK head E_INVALIDARG <-- main accepted it
extensible cbSize 0 main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG
That is the negative control I can give without Windows: the byte-rate case in particular was accepted by main, because valid_format never looked at nAvgBytesPerSec, so the test catches a real hole and not just a different HRESULT. wBitsPerSample % 8 is required by valid_format and not by malformed_format, so a 12- or 20-bit container is now E_INVALIDARG where it used to be E_UNSUPPORTED_FORMAT; both are refusals of a format the shim never took, so that is only an HRESULT change.
Reading the rest of the change
IsFormatSupportednulls*closestat entry (:273), so the new early return leaves it null and the test's!closestholds.init()hasif (!format) return E_POINTERbefore the lock (:451), somalformed_formatnever sees null; movingLock l(lock_)abovevalid_formatis safe.valid_formatguardscbSize >= 22in both places it reads the extension (is_floatand its own EXTENSIBLE branch), so thecbSize < 22case was already not an out-of-bounds read; the new check makes it a refusal with the right HRESULT, not a crash fix.AudioClient::GetServicewrites*ppv = nullptrfirst (:641), so returningAUDCLNT_E_WRONG_ENDPOINT_TYPEforIAudioCaptureClientleaves the out pointer null as the test expects, and theE_NOINTERFACElog path is untouched.release_bufferchecks flags after thepending_check and before the size, and returns before touchingpending_, which is what the test's "packet stays pending, then ReleaseBuffer(frames, 0) succeeds" relies on.- The
Resetchange removes theS_FALSEearly return, and nothing in the runtime callsIAudioClient::Reset(git grepoverruntime/finds only allocator/listReset), so no other shim depends on the old answer. - Note that a malformed format in
AUDCLNT_SHAREMODE_EXCLUSIVEstill getsAUDCLNT_E_UNSUPPORTED_FORMAT, because the mode branch comes first; the new rule therefore holds for shared mode, which is the only mode the shim accepts anyway.
Findings
-
Signed overflow on the garbage it is meant to reject -
runtime/shims/silent_audio.cpp:128:f->nChannels * f->wBitsPerSample / 8multiplies twoWORDs after integer promotion toint, so a caller passingnChannels = 65535, wBitsPerSample = 65535overflowsint. UBSan on the extracted function aborts withsigned integer overflow: 65535 * 65535 cannot be represented in type 'int'before the function can returntrue. This is reachable fromIsFormatSupportedandInitializewith a title-supplied struct, in the one function whose job is to classify exactly that input. One cast fixes it and matches the line below:static_cast<uint64_t>(f->nChannels) * f->wBitsPerSample / 8. -
The shim's documented answers are now stale -
docs/runtime_imports.md:277enumerates what the silent endpoint answers ("GetServicegivesIAudioRenderClient,IAudioClock,ISimpleAudioVolumeandIAudioStreamVolume", "The client takes any PCM or float format in shared mode"). After this PR the paragraph is missing three measured answers:IAudioCaptureClienton a render endpoint isAUDCLNT_E_WRONG_ENDPOINT_TYPE, a malformed format isE_INVALIDARGrather thanAUDCLNT_E_UNSUPPORTED_FORMAT, and aResetwith nothing to reset isS_OK. The file's habit elsewhere is to record the host's answer next to the behaviour, and these are the kind of detail a title's error path turns on, so a sentence there is worth the three lines. -
Nit in the new test -
runtime/test/silent_audio_test.cpp:385-397:closestis initialised tonullptrand the refusal returns before it can be written, so|| closestcannot fail; it would pin "not written" only if it started as a non-null poison value. Harmless, but it is the one check in the loop that cannot bite.
No regressions to measure on this side: no translator, harness or GPU code changes, so the shader fixtures were not re-run; the same-main baseline stands (195 PASS / 3 FAIL / 70 SKIP MoltenVK, 190 / 5 / 73 KosmicKrisp).
python -I scripts/check_no_game_data.py runtime/shims/silent_audio.cpp runtime/test/silent_audio_test.cpp: clean.
No game files. AI-assisted.
Claimed in the coordination issue as: SILENT-AUDIO-HOST-ANSWERS
What and why
I ran the same
IAudioClient/IAudioRenderClientcalls against the host's default render endpoint and against the silent endpoint (LEONIDA_AUDIO=silent), side by side in one probe built withsilent_audio.cpp, on Windows 11, with a fresh client for each case. Most answers already match. Four calls answer differently:mainInitialize/IsFormatSupportedwith a malformedWAVEFORMATEX:nChannels,nSamplesPerSecorwBitsPerSample0,nBlockAlignornAvgBytesPerSecnot following from them,WAVE_FORMAT_EXTENSIBLEwithcbSize< 22E_INVALIDARGAUDCLNT_E_UNSUPPORTED_FORMAT; a wrongnAvgBytesPerSecwas taken as a valid formatInitializewith a malformed format on a client that is already initializedAUDCLNT_E_ALREADY_INITIALIZEDAUDCLNT_E_UNSUPPORTED_FORMAT(the format was checked first)GetService(IAudioCaptureClient)on the render clientAUDCLNT_E_WRONG_ENDPOINT_TYPEE_NOINTERFACEResetwhen there is nothing to reset (never started, or reset already)S_OKS_FALSEIAudioRenderClient::ReleaseBuffer(n, flags),n> 0, with any flag butAUDCLNT_BUFFERFLAGS_SILENTand bit 31 (one bit at a time over all 32)E_INVALIDARG, checked before the size, and the packet stays pendingEach is now answered as the host does. The order of the checks follows the host too:
closestis stillE_POINTERfirst;ReleaseBufferwith nothing pending is stillAUDCLNT_E_OUT_OF_ORDERbefore the flags are read;ReleaseBufferdoes not look at the flags (the host returnsS_OKthere).Not changed, because the answers depend on the device and engine rather than on the call: which well-formed formats are supported (the shim takes any PCM or float format on purpose), the
Initializestream-flag checks (the host's answers per bit are irregular), and the host's ownInitializerefusal of 12-bit or 64-channel formats.Tested
Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:
silent_audio_testgets five checks, matching the table:IsFormatSupportedandInitializeare bothE_INVALIDARG, and nothing comes back inclosest;AUDCLNT_E_ALREADY_INITIALIZED;GetService(IAudioCaptureClient)isAUDCLNT_E_WRONG_ENDPOINT_TYPE;Resets of an unused stream areS_OK;ReleaseBufferwithDATA_DISCONTINUITY,0x10, and0x4with an oversized count isE_INVALIDARG, and the packet is still released afterwards.On
main, 5 checks fail, plus one follow-on: main released the packet on the bad flag, so the later release of it fails. With this branch, 134 of 134 pass.Merged together with silent_audio: an empty GetBuffer packet leaves nothing pending (SILENT-AUDIO-EMPTY-PACKET) #2133 and silent_audio: pace the 10 ms passes with a high-resolution timer (SILENT-AUDIO-PASS-CADENCE) #2134, which also change this file and test: 139 of 139 pass. Both merge cleanly with it (
scripts/pr_overlap.pyfrom scripts: pr_overlap.py lists the open pull requests that change the same files (PR-OVERLAP-CHECK) #2349).scripts/check_no_game_data.pyon both files.Not tested under Wine.
GPUs tested: n/a (CPU tests)
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code