Repository navigation
io: Bound WAV lengths to physically available audio - #525
Merged
Merged
Conversation
Problem The new WAV tests produce 11 errors in CI's Python type-check job because an extensible-header GUID can be None and callback streams do not declare the binary-I/O interface expected by AudioFile's overloads. Solution Narrow the optional GUID before constructing an extensible header and use the existing BinaryIO adapter convention for the bounded callback stream. Result CI's pinned pyright reports zero errors across the package and test files. All 140 WAV regression cases pass with callback behavior preserved.
Problem The initial length fix imposed additional malformed-header validation and rejected layouts that the existing decoder accepted. That exceeds the scope of correcting audio declarations that extend past physical EOF. Solution Restore the original codec dispatch and delegate format acceptance to JUCE. Isolate a best-effort lookup of the selected payload and decoder stride, following repeated-chunk and RF64 traversal without new rejection paths. Bound the native reader by physical availability only after JUCE constructs it, and retain shorter declarations and legacy stream behavior. Add baseline compatibility controls and regressions for understated RIFF boundaries, normalized float32 headers, repeated selected payloads and failed seeks. Document the narrower recovery contract. Result All 286 WAV tests pass and CI's pinned type checker reports zero errors. The full suite reports 27,215 passes, four skips and only the previously observed threaded-versus-serial I/O timing failure.
cjacoby-sptfy
marked this pull request as ready for review
October 23, 2026 23:18
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.
Problem
A finite, seekable WAV can declare more audio data than physically exists.
For example, a 100 ms stereo PCM16 file at 48 kHz with a data size of
0xFFFFFFFF reports over six hours of audio. This can cause oversized buffer
allocations and resampling or writing of silence past physical EOF.
We discovered this while ingesting a new dataset which had a couple of files
with malformed wav headers.
Solution
Locate the audio JUCE selects and calculate how many complete frames fit
between its start and physical EOF. Use JUCE's decoding rules for frame
size, then lower its reported frame count only when it exceeds that limit.
Keep existing format acceptance and codec selection. Add regression tests
for supported PCM/float32 WAV and RF64 layouts, plus compatibility checks
against 0.9.26. A version guard flags future JUCE upgrades for review.
Result
For supported inputs, overstated lengths no longer make reads or resampling
continue through nonexistent audio. Shorter declarations and unrelated
decoder behavior stay as before.
Recovery needs a known stream length and an identifiable audio layout. It
cannot distinguish audio from trailing metadata swallowed by an oversized
data chunk, so those bytes can still be decoded as audio.
Local validation on macOS arm64:
previously observed threading-performance failure.
has the same 17 existing diagnostics. Cross-platform checks run in CI.