Skip to content

bug: libobs: enum_audio_devices doesn't check its allocation #2862

Closed

Description

@rdoupe

Location

libobs/audio-monitoring/osx/coreaudio-enum-devices.c.h on master at 0c92fef, enum_audio_devices() (58-84):

ids = malloc(size);
count = size / sizeof(AudioDeviceID);

stat = AudioObjectGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, ids);
if (success(stat, "get data")) {
	for (UInt32 i = 0; i < count; i++) {
		if (!obs_enum_audio_monitoring_device(cb, data, ids[i], allow_inputs))

Class

Unchecked allocation: NULL dereference when malloc fails.

How it is reached

Every walk of the CoreAudio device list on macOS goes through it: obs_enum_audio_monitoring_devices() (the monitoring device list in Settings → Audio), devices_match() and get_desktop_default_id(). When malloc(size) returns NULL, the NULL is handed to AudioObjectGetPropertyData() as the output buffer for size bytes, and if that call reports success the loop reads ids[i] from NULL. Only an allocation failure triggers it. No upstream issue.

Proposed fix and failing test

Return when ids is NULL, before the property read: the caller sees an empty device list, as it does when the size query fails.

RED: a cmocka test, test_coreaudio_enum_alloc, that compiles coreaudio-enum-devices.c.h over stand-ins for the CoreAudio calls and a malloc that can be made to fail (no Apple headers, so it builds on Linux). With the allocation failing, obs_enum_audio_monitoring_devices() must not read the device list into NULL and must not call the callback. A second case with a working allocator pins the normal walk (every output device reported, in order, stopping at the first false). GREEN: the NULL check.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2862.

    1. RED: test_coreaudio_enum_alloc, a cmocka test that compiles coreaudio-enum-devices.c.h over CoreAudio stand-ins and a failing malloc (builds on Linux, no Apple headers). With the allocation failing, the device list isn't read into NULL and the callback isn't called; with it working, the normal walk is pinned.
    2. GREEN: return from enum_audio_devices() when ids is NULL, before the property read.

    Draft PR with the RED commit within the hour.

  3. added
    ready
    on Oct 29, 2026
  4. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by #2863 (merged as 32c4bcc): enum_audio_devices() in libobs/audio-monitoring/osx/coreaudio-enum-devices.c.h now returns an empty device list when its allocation fails, instead of asking CoreAudio to write the device ids into NULL. The new test_coreaudio_enum_alloc (7 cases, run in the Linux Tier 2 lane) failed 3 of 7 before the fix and passes now.

    What is left: the new test has only been built on Linux, with CoreAudio stand-ins, so no native macOS or Windows Tier 2 run has built it. The macOS Tier 2 lane on master pushes covers that, and the file's port is covered by its own port issue.

    Follow-up issue: none. Nothing in the code is left to fix.

  5. moved this from In merge queue to Done in obs-rust Multiviewon Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions