Fix FLAC binary seek livelock when byte range collapses - #1145
Open
zhou13 wants to merge 1 commit into
Open
Conversation
zhou13
marked this pull request as ready for review
August 4, 2026 22:01
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.
The deadlock is rare but does happen with some FLAC files.
What changed
Root cause
For a native FLAC without a seek table, seeking to PCM frame
6371359narrows the binary search to bytes6242259and6242260. Resynchronizing at those offsets finds FLAC frames beginning at PCM6368256and6371712, respectively. The target lies between them, but there is no byte midpoint left and the earlier frame is just beyond the existing two-block forward threshold. The search therefore alternates between the same two offsets indefinitely.The input is a 16-bit mono 16 kHz FLAC with 10,430,775 samples and no seek table (
sha256:907a1d60713ce6e058656b85c827568546a3f1df08105bf8bd43af0036a2edd3). The issue reproduces on currentdevwith this minimal program:Before this change, the program consumes CPU until externally killed. With this change, the seek returns immediately.
Validation
MINIAUDIO_FORCE_C89=ON; the focused reproducer also completed cleanly under UBSan.By submitting this pull request, I agree to release this contribution under miniaudio's public-domain/MIT-0 terms.