fix: prevent integer overflow in AudioSourceFactory frame count calculation#813
Open
jtjones1028 wants to merge 1 commit into
Open
fix: prevent integer overflow in AudioSourceFactory frame count calculation#813jtjones1028 wants to merge 1 commit into
jtjones1028 wants to merge 1 commit into
Conversation
…lation Fixes a crash when processing audio files where (audioFile.length - audioFile.framePosition) exceeds AVAudioFrameCount.max (UInt32.max = ~4.29 billion frames). The bug caused a Swift runtime failure: "Not enough bits to represent the passed value" when casting Int64 to UInt32 without bounds checking. This occurred during initialization in apps using FluidAudio for diarization, particularly when Speech API capability checks triggered audio processing. Solution: Clamp the remaining frames to AVAudioFrameCount.max before casting, preventing overflow while maintaining correct behavior for normal-sized audio files.
Member
|
from claude the only other signal; my review from the previous message stands as the only feedback so far:
|
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.
Summary
Fixes a crash when processing audio files where
(audioFile.length - audioFile.framePosition)exceedsAVAudioFrameCount.max(UInt32.max = ~4.29 billion frames).Problem
The bug caused a Swift runtime failure: "Not enough bits to represent the passed value" when casting
Int64toUInt32without bounds checking inAudioSourceFactory.swift:138.This occurred during initialization in macOS apps using FluidAudio for diarization, particularly when Speech API capability checks triggered audio processing with test/probe audio files.
Solution
Clamp the remaining frames to
AVAudioFrameCount.maxbefore casting:This prevents overflow while maintaining correct behavior for normal-sized audio files.
Testing
swift buildBackport Request
This fix should be backported to the 0.14.x maintenance branch as well, as it affects apps using FluidAudio 0.14.5-0.14.8.