Skip to content

MP4: Fix freeform atom size validation - #599

Merged
Serial-ATA merged 1 commit into
Serial-ATA:mainfrom
M0Rf30:fix/mp4
Feb 8, 2026
Merged

Serial-ATA merged 1 commit into
Serial-ATA:mainfrom
M0Rf30:fix/mp4

Conversation

@M0Rf30

@M0Rf30 M0Rf30 commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Change freeform chunk size check from >= to > to allow atoms that exactly fill the remaining space

@M0Rf30

M0Rf30 commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

Issue

M4A files with embedded cover art fail to extract artwork. The parser stops prematurely when encountering iTunes freeform atoms (----), never reaching the covr (cover art) atom.

Root Cause

In lofty/src/mp4/atom_info.rs:276, the freeform chunk size validation incorrectly rejects atoms whose size exactly matches the remaining buffer space:

// Before (incorrect)
if len >= *reader_size {
    err!(SizeMismatch);
}
// After (correct)  
if len > *reader_size {
    err!(SizeMismatch);
}

Fix

Changed >= to > to allow atoms that perfectly fill remaining space, which is valid per MP4 spec.

Testing

  • Tested with M4A files containing iTunes metadata and embedded cover art
  • Parser now successfully processes all atoms including covr
  • Cover art extraction works correctly

@M0Rf30

M0Rf30 commented Feb 7, 2026

Copy link
Copy Markdown
Contributor Author

Any news about this?

@Serial-ATA

Copy link
Copy Markdown
Owner

Hey @M0Rf30, this makes sense. Just curious, do you have a file that triggers this? I don't think I've ever encountered a freeform atom without data

@M0Rf30

M0Rf30 commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

Hey @M0Rf30, this makes sense. Just curious, do you have a file that triggers this? I don't think I've ever encountered a freeform atom without data

of course
01.zip

set the extension of downloaded file back to m4a

@Serial-ATA

Copy link
Copy Markdown
Owner

Ah interesting, it just has a bunch of holes in the data. I was expecting some flag atoms. Still valid in any case.

@Serial-ATA
Serial-ATA merged commit 568813e into Serial-ATA:main Feb 8, 2026
4 checks passed
@M0Rf30
M0Rf30 deleted the fix/mp4 branch February 8, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants