Repository navigation
Fingerprint truncated MP4/M4A files with overrun mdat size - #4
Merged
Merged
Conversation
Truncated .m4a files (interrupted download/copy) keep an mdat box header advertising the original size, which now runs past EOF. Symphonia's isomp4 demuxer discards such an mdat and fails with "no atom pending read", even though the audio present decodes fine. Detect a final mdat whose declared end exceeds the file length and rewrite its size field to the bytes on disk via a MediaSource wrapper, so the available audio is fingerprinted (symphonia then stops at a clean EOF). Also break on a demuxer DecodeError instead of failing the whole file.
zas
requested changes
Jul 10, 2026
zas
left a comment
Owner
There was a problem hiding this comment.
Thanks for your patch, overall it looks good, but I think we can improve it slightly, see my comments.
Address review feedback on PR zas#4: - Move the mdat scan and PatchedSource into a new src/container_repair/ module with a format-specific mp4 submodule, a shared Patch type, and a single detect_repairs(file, path, len) entry point, so future format repairs are just a new submodule and one match arm. - Pass the already-open File into the scan instead of reopening the path, removing the redundant open and the race between the two opens. The scan rewinds the shared cursor when done. - Add unit tests for the 32-bit and 64-bit mdat size repairs.
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.
Some MP4/M4A files declare an
mdatbox size that overruns the actual file length (e.g. truncated downloads). These previously failed to fingerprint. This handles the overrun by clamping to the real file size so the audio can still be decoded and fingerprinted.