AmB2BMedia::writeStream: guard zero sample rate to prevent SIGFPE crash#551
Open
hecko wants to merge 1 commit into
Open
AmB2BMedia::writeStream: guard zero sample rate to prevent SIGFPE crash#551hecko wants to merge 1 commit into
hecko wants to merge 1 commit into
Conversation
…FPE) AudioStreamData::writeStream fetches sample_rate = stream->getSampleRate() and passes it as the output sample rate into the AmAudio get()/put() chain. getSampleRate() returns 0 when the stream format is not set yet or a zero-clock-rate codec was negotiated, and that value is used as a divisor in AmBufferedAudio::get (nb_samples * getSampleRate() / output_sample_rate), raising SIGFPE and taking down the whole process on the B2B/SBC media path. Return early when sample_rate == 0, mirroring the guard already present in AmSession::writeStreams. Backport of yeti-switch/sems dc7aa556.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds a safeguard in the B2B media send path to prevent a divide-by-zero (SIGFPE) crash when the stream sample rate is still unset (0).
Changes:
- Early-return from
AudioStreamData::writeStreamwhenstream->getSampleRate()returns0 - Documents why the guard is needed and aligns behavior with
AmSession::writeStreams
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Bug
AudioStreamData::writeStream(core/AmB2BMedia.cpp) does:getSampleRate()returns0when the stream format is not yet set (or a zero-clock-rate codec was negotiated).sample_rateis then used as the divisor deeper in theAmAudiochain — e.g.AmBufferedAudio::get:With
output_sample_rate == 0this is an integer divide-by-zero → SIGFPE, whole process crash. It is reachable on the B2B/SBC media path whenever a leg with a custom input (announcement / hold music / playback = anAmBufferedAudio) is attached to a stream whose sample rate is still 0.Fix
Return early when
sample_rate == 0, before anyget()/put()call. This mirrors the identical guard already merged forAmSession::writeStreams(#542); this parallel B2B path was left unpatched.Validation
masterand that the divide sink (AmBufferedAudio::get,core/AmBufferedAudio.cpp:90) performs integer division byoutput_sample_rate.AmSession::writeStreamsalready carries the equivalent guard (with the same SIGFPE comment), so this only closes the remaining sibling gap.Acknowledgement
Backport of the fix from the yeti-switch/sems fork, commit
dc7aa5563d705eb7be1ee46706a9eda18fbbeb88("AmSession,AmB2BMedia::writeStreams: return 0 on zero output_sample_rate"). Thanks to the yeti-switch maintainers.Generated by Claude Code