Skip to content

Audio & Voice Commands: SystemAudioRecorder.teardown() data race on MixWriter.summary, unchecked Int(CFHash) overflow crash, and ignored pinned mic #340

Open

Description

@Pizzylee001

Summary

Three verified bugs in SystemAudioRecorder and SystemVoiceCommandPerformer:

  1. Data race / potential crash in SystemAudioRecorder.teardown()

    • Sources/BlurtEngine/Audio/SystemAudioRecorder.swift:110-120 reads writer.summary on the caller thread (MainActor) before calling AudioDeviceStop/AudioDeviceDestroyIOProcID and before queue.sync { writer?.close() }.
    • MixWriter (SystemAudioMix.swift:16-18,36-43,113) is @unchecked Sendable confined to queue, and summary reads callbacks, framesIn, framesOut, and ARC-managed lastError: String? while the CoreAudio IOProc is actively mutating them on queue.
  2. Unchecked Int(CFHash($0)) traps with integer overflow in Release builds

    • Sources/BlurtEngine/Command/SystemVoiceCommandPerformer+Screen.swift:239 converts CFHashCode (UInt, 64-bit unsigned) via checked Int(CFHash($0)) into PressFingerprint.focusedElement: Int? (ScreenContext.swift:298).
    • Whenever bit 63 is set (>= 0x8000_0000_0000_0000), Swift traps in both Debug and Release builds. fingerprint runs on every press in Chromium/Electron and every select in any app.
  3. SystemAudioRecorder ignores the user's pinned microphone in MicDeviceStore

    • Sources/BlurtEngine/Audio/SystemAudioRecorder.swift:146 always binds the CoreAudio aggregate sub-device to AudioInputDevices.systemDefaultDevice?.uniqueID, ignoring MicDeviceStore().selection.pinnedUID (which Settings › Microphone promises is "Used for voice recording"). Users whose macOS default input is a virtual loopback device silently lose their mic track on meeting recordings.

Suggested Fix

  • Read writer?.summary inside queue.sync after stopping/destroying the IOProc.
  • Use UInt? (or Int(bitPattern: CFHash($0))) for PressFingerprint.focusedElement.
  • Resolve MicDeviceStore().selection.pinnedUID.flatMap(AudioInputDevices.device(forUID:)) ?? AudioInputDevices.systemDefaultDevice in createAggregate().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions