Repository navigation
silent_audio: NaN volumes refused, master volume under the lock, Reset revokes objects (RT-SILENT-AUDIO-VOLUME-AND-SPATIAL) - #2521
Conversation
…t revokes objects (RT-SILENT-AUDIO-VOLUME-AND-SPATIAL) From kevincommits' finding on ProjectLeonida#1608 (item 4): - SimpleVolume::SetMasterVolume, StreamVolume::SetChannelVolume and StreamVolume::SetAllVolumes refuse NaN. They tested `level < 0.0f || level > 1.0f`, which is false for NaN, and stored it. One helper checks `level >= 0.0f && level <= 1.0f`, as SpatialObject::SetVolume does. - ISimpleAudioVolume's master volume and mute are kept under the client's lock, like the channel volumes, instead of read and written bare. - SpatialStream::Reset revokes every active object, as Microsoft's reference for ISpatialAudioObjectRenderStreamBase::Reset says: each is inactive, its type can be activated again, and queued ends are dropped. The stream keeps a list of its live objects (not owned); an object leaves it first thing in its destructor. Not changed: ActivateSpatialAudioObject during an update pass. The reference lists no SPTLAUDCLNT_E_OUT_OF_ORDER for it, and activating objects inside a pass is the documented pattern (this file's own test does it). 6 new checks in silent_audio_test fail on main and pass with the fix. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed at head Verification
Findings (Request changes)
The NaN volume rejection and locked master volume/mute access ( AI-assisted review + local MSVC verification. |
|
#2521 | head 53ea681 (merged cleanly with main 09c1539) | |
timbot103
left a comment
There was a problem hiding this comment.
Request changes after a static code audit against 53ea681a0 + ec740bcc3. The range checks reject NaN, and the master volume and mute accessors consistently take the client lock.
runtime/shims/silent_audio.cpp:821,:830and:895— Reset can run between type reservation and registration, or between unregistering and freeing a type. Either window can allow two active objects for one static type. Update the registry and reservation in one critical section on activation and final release.runtime/shims/silent_audio.cpp:830— A failed registry insertion throws out of the COM method and leaks the object, its stream reference and the type reservation. Use fixed slots or roll back and returnE_OUTOFMEMORY.runtime/shims/silent_audio.cpp:844and:907— An in-flightSetEndOfStreamcan enqueue a revoked object after Reset drains the queue, keeping the object and stream alive if no later call drains it. Recheck activity under the stream lock before enqueueing.runtime/shims/silent_audio.cpp:719— A validSetVolumecall still succeeds on an object revoked by Reset. ReturnSPTLAUDCLNT_E_RESOURCES_INVALIDATEDfor that object.
The tests cover NaN refusal and sequential revocation. Cover the Reset races and allocation failure with deterministic tests, and make the existing reactivation check require a successful Begin.
AI-assisted.
Package RT-SILENT-AUDIO-VOLUME-AND-SPATIAL: item 4 of @kevincommits' finding on #1608 (#1608 (comment)). Thank you for the find. Claim: #1608 (comment).
What changes (
runtime/shims/silent_audio.cpp)SimpleVolume::SetMasterVolume,StreamVolume::SetChannelVolumeandStreamVolume::SetAllVolumestestedlevel < 0.0f || level > 1.0f. That is false for NaN, so NaN was stored. One helper now checkslevel >= 0.0f && level <= 1.0f, asSpatialObject::SetVolumealready does.ISimpleAudioVolumeread and wroteclient_->master_andmute_with no lock. They are now private, behind accessors that takelock_, like the channel volumes.SpatialStream::Resetrevokes active objects. Microsoft's reference forISpatialAudioObjectRenderStreamBase::Resetsays resetting "causes all active ISpatialAudioObject instances to be revoked". Now each live object becomes inactive and its type can be activated again. Ends that a pass had queued are released. The stream keeps a list of its live objects (not owned). An object leaves the list first thing in its destructor, so a Reset that holds the lock still sees the whole object.Not changed:
ActivateSpatialAudioObjectduring an update pass. The finding suggests returningSPTLAUDCLNT_E_OUT_OF_ORDERthere. Microsoft's reference for that method lists no such return code. Activating objects inside a Begin/End pass is the documented pattern for dynamic objects, andsilent_audio_testitself activates its static objects that way. So this PR leaves it as it is.Tests (
silent_audio_test)SetMasterVolume(NaN),SetChannelVolume(7, NaN)andSetAllVolumeswith one NaN level are each refused, and the stored volumes stay as they were.StopandReset, a front-left object that was active reportsIsActive == FALSE.GetBufferon it givesSPTLAUDCLNT_E_RESOURCES_INVALIDATED. Front left can be activated again; on main that givesSPTLAUDCLNT_E_OBJECT_ALREADY_ACTIVE.On main, 6 of the new checks fail. With the fix, all 135 checks pass (3 runs).
The lock change has no test of its own: a data race on a float does not show up in a test. It now follows the same pattern as the channel volumes.
Profile M: RTX 4070 SUPER, Windows 11, Ryzen 7 9800X3D, MSVC RelWithDebInfo. CPU only. The full suite was not run because a boot was running.
git diff --checkandscripts/check_no_game_data.pyare clean. Open PRs #2133, #2134 and #2387 change other functions in this file. No game files used.AI-assisted (Claude Code).
🤖 Generated with Claude Code