Repository navigation
libobs: Check the CoreAudio device list allocation - #2863
Conversation
|
Status from the coordinator: the branch is red on its latest run (40815028760) in Tier 2 Linux (tests OFF): |
d115f48 to
342cbfe
Compare
|
Coordinator: the branch is green now, so the only thing left before the queue is marking it ready.
Still a draft, so no queue action from me. Mark it ready when you are satisfied and I will put it in the merge queue on the next tick. |
zackees
left a comment
There was a problem hiding this comment.
Coordinator review (no changes requested; the queue entry stands).
Verified in the diff
- The fix is the minimal correct one.
ids = malloc(size); if (!ids) return;sits before the property read, so the failure path is exactly the one the size query already takes (empty list), nothing is logged that was not logged before, and thefree(ids)at the end is skipped only whenidsis NULL, so there is no leak.countis still derived fromsizeand is now only used on the success path. - RED is honest. The fake HAL counts a read of the device list into NULL and refuses it, so the old code fails
test_failed_allocation_reads_nothingondevice_list_readsinstead of crashing the test, and the four cases that pin the normal walk (device order, the input-only device skipped throughkAudioDevicePropertyStreams, stop at the firstfalse) show the assertions are not vacuous. - Every entry point the bug reached is covered:
obs_enum_audio_monitoring_devices(),devices_match()(both the equal-UID and the"default"path) andget_desktop_default_id()(system default is not a loopback, so the loopback walk runs; and thebzalloc(1)empty-string fallback). I traced those three paths againstcoreaudio-enum-devices.c.hand the expected values match, including""for the failed-allocation case. - Housekeeping is right: the ledger line is in
docs/features.md, the test is registered intest/cmocka/build/test-graph.jsonwithaddress,undefined, and the graph's partitions still cover every test and target (rust/obs-build/tests/native.rsasserts that, and CI Gate is green). - No C test or public header is touched, and the changed file is macOS-only, so the Linux C, hybrid and C-reference symbol sets do not move.
Notes, none blocking
- The stub reimplements
astrstri()andcfstr_copy_cstr(), sodevice_is_input()is exercised against the copy rather than libobs's. That is the right trade for a test that links no libobs, and the stub says so ("As libobs's: ASCII case only"); it is worth keeping that sentence if the stub is ever extended, because a change in libobs's folding semantics would otherwise not show up here. enum_audio_devices()returns beforecountis used, socountcould move below the check as a one-line tidy. Not worth a commit on its own; fold it in if this file is touched again.- The description is honest that no native macOS or Windows Tier 2 run built the test. The stubs are portable and the source under test is macOS-only, so nothing else needs a lane for it; the macOS verdict comes from the file compiling there, which the
macOS 🍏lane covers.
Reviewed by the coordinator on 2026-10-29.
|
Thanks for the review. On the notes:
On the two queue ejections (runs 40840984942 and 40847888429): both failed only Rust Tier 2 (macos-26), on four conversion errors in |
Why this left the merge queue (coordinator, 2026-10-29)Not your diff. The merge group for pr-2863 ( Keeping your lease and the requeue: once #2897 lands I will rebase this onto the new master and put it back in the queue in the same tick. Nothing needed from you. |
342cbfe to
5dbb0dd
Compare
enum_audio_devices() allocates the CoreAudio device list with malloc() and reads the list into it without checking the result. A failed allocation hands NULL to AudioObjectGetPropertyData() as the output buffer, and if that call succeeds the loop reads the ids from NULL. test_coreaudio_enum_alloc compiles coreaudio-enum-devices.c over stand-ins for CoreAudio, CoreFoundation and the libobs calls it makes, found first as build/libobs-macos.pch.h, so it needs no macOS SDK. The fake HAL counts a read of the device list into NULL and refuses it, so the bug fails the test instead of crashing it. With malloc failing, obs_enum_audio_monitoring_devices(), devices_match() and get_desktop_default_id() must not read the list at all; the other cases pin the normal walk. Refs #2862.
enum_audio_devices() passed the result of malloc() straight to AudioObjectGetPropertyData() as the output buffer, so a failed allocation asked CoreAudio to write the device ids into NULL, and on success the loop read them from NULL. Return when the allocation fails, before the property read: the caller sees an empty device list, as it does when the size query fails. The calls keep their order and no log message changes. Refs #2862.
5dbb0dd to
a906b02
Compare
Fixes #2862
What and why
enum_audio_devices()inlibobs/audio-monitoring/osx/coreaudio-enum-devices.c.hallocates the CoreAudio device list withmalloc()and passes the result straight toAudioObjectGetPropertyData()as the output buffer. When the allocation fails, CoreAudio is asked to write the device ids into NULL, and if it reports success the loop readsids[i]from NULL. Every walk of the device list goes through it: the monitoring device list,devices_match()andget_desktop_default_id().The fix returns when
idsis NULL, before the property read, so the caller sees an empty device list, as it already does when the size query fails. Every call and read stays where it was and under its condition, and no log message changes. The same code is in upstream obs-studio (no upstream issue).The new test,
test_coreaudio_enum_alloc, compiles the file over stand-ins for CoreAudio, CoreFoundation and the libobs calls it makes (test/cmocka/coreaudio-enum-stubs/, found first asbuild/libobs-macos.pch.h), so it needs no Apple header or macOS SDK. It has been built and run only on Linux (gcc and clang, locally; PR CI runs it in the Linux Tier 2 lane); no native macOS or Windows Tier 2 run has built it. The fake HAL counts a read of the device list into NULL and refuses it with an error, so the bug fails the test instead of crashing it. It runs under ASan and UBSan.RED → GREEN
test: Fail the CoreAudio device list allocation).test_coreaudio_enum_allocfails 3 of 7:test_failed_allocation_reads_nothing,test_devices_match_failed_allocationandtest_desktop_default_failed_allocation(the device list is read into NULL once, twice and once); the four cases that pin the normal walk pass. Built with gcc (ASan/UBSan) and clang.libobs: Check the CoreAudio device list allocation).test_coreaudio_enum_allocpasses 7/7 (gcc with ASan/UBSan, clang) and runs under ctest. The local gate's--test-diff origin/master(whole workspace: 4870 Rust tests, 0 failed, 6 skipped as on master),lintandcrosslanes pass, andsoldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targetsis clean; runs were on bd5fdc2. The changed file builds only on macOS, so the exported symbol sets of the Linux C, hybrid and C-reference libobs don't change. The full Linux Tier 2 suite was not run locally (no Docker access on the build machine), so the head is not stamped and PR CI runs the full suite.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (Fixed upstream bugs, Stability)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)