Repository navigation
fix(linux): prevent SIGABRT crash when setting volume to 0% - #54
Merged
Merged
Conversation
ChannelVolumes::default() has 0 channels and is rejected as invalid by PulseAudio (pa_cvolume_valid returns false). When setting volume to 0%, the previous code skipped channel volume initialization, passing the empty structure to set_sink_volume_by_name / set_source_volume_by_name. PulseAudio returned a NULL operation pointer, triggering an assertion panic in libpulse-binding and SIGABRT. Now channel_volumes_for guarantees valid ChannelVolumes with CHANNELS_MAX channels set to Volume::MUTED whenever scalar <= 0 or is NaN, and device names are validated against empty strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a SIGABRT crash on Linux when a device volume is set to 0%.
set_device_volumeskipped channel initialization whenscalar <= 0, so an emptyChannelVolumes::default()(0 channels) was passed toset_sink_volume_by_name/set_source_volume_by_name. libpulse rejects it client-side (pa_cvolume_validfails) and returns a NULL operation, which trips an assertion inlibpulse-bindingand aborts the process.Changes in
src-tauri/src/audio/volume/linux.rs:channel_volumes_for(scalar)always returns a validChannelVolumes:<= 0andNaNmap toVolume::MUTEDon all channels, positive values keep the existing cubic mapping.set_device_volumereturnsfalseif the volumes are invalid instead of handing them to PulseAudio.resolve_devicerejects empty / whitespace names (including an emptymonitor:suffix and an empty default sink/source from the server), since an empty name also makes libpulse return a NULL operation.channel_volumes_for(zero, negative, NaN, positive) anddevice_volume_from.All Linux volume writes go through
set_device_volume, so the fix covers output devices (speakers), input devices (microphones) andmonitor:sources (system / app audio). There is no per-app sink-input / source-output volume control on Linux, so no other call sites are affected.Why is this the right approach?
The crash comes from building an invalid
ChannelVolumes, so the fix makes the builder always produce a valid one instead of catching the failure later. Muting is expressed asVolume::MUTEDon every channel plus the existingset_*_mute_by_namecall, which is what PulseAudio expects for 0%. Validating the device name inresolve_devicecloses the other client-side path that returns a NULL operation. No new dependencies.Checklist
bun run checkpassescargo check --manifest-path src-tauri/Cargo.tomlpassesbun run formatleaves the tree cleanDspWorker::runPlatform coverage
Per-OS file touched:
src-tauri/src/audio/volume/linux.rsonly. macOS (volume/macos.rs) and Windows (volume/windows.rs) are not affected.Related