Skip to content

Commit 8119f56

Browse files
committed
MP4: Demote atom size mismatch error for free
If a `free` atom claims to be larger than the remainder of the stream, parsing will simply stop. This will now only be a `SizeMismatch` error in `Strict` mode. Invalid padding is a common issue in all tag formats due to buggy software, so it's better to work around it by default rather than discard the entire stream as invalid.
1 parent 933a631 commit 8119f56

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Changed
1010

11-
* **MP4**: A missing `mdat` atom is no longer a hard error when reading properties ([PR](https://github.com/Serial-ATA/lofty-rs/pull/515))
12-
* This is now only an error in `Strict` mode. Note that any properties read in a file with no `mdat` atom are essentially useless.
11+
* **MP4**:
12+
* A missing `mdat` atom is no longer a hard error when reading properties ([PR](https://github.com/Serial-ATA/lofty-rs/pull/515))
13+
* This is now only an error in `Strict` mode. Note that any properties read in a file with no `mdat` atom are essentially useless.
14+
* Incorrectly sized `free` atoms are no longer a hard error ([PR](https://github.com/Serial-ATA/lofty-rs/pull/516))
15+
* If a `free` atom claims to be larger than the remainder of the stream, parsing will simply stop. This will now only
16+
be a `SizeMismatch` error in `Strict` mode. Invalid padding is a common issue in all tag formats due to buggy software,
17+
so it's better to work around it by default rather than discard the entire stream as invalid.
1318

1419
## [0.22.3] - 2025-04-04
1520

lofty/src/mp4/atom_info.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ impl AtomInfo {
182182
if (len - ATOM_HEADER_LEN) > reader_size {
183183
log::warn!("Encountered an atom with an invalid length, stopping");
184184

185-
if parse_mode == ParsingMode::Relaxed {
185+
// As with all formats, there's a good chance certain software won't know how to actually use padding.
186+
// If the file ends with an incorrectly sized padding atom, we can just ignore it.
187+
let skippable = (parse_mode != ParsingMode::Strict && identifier == *b"free")
188+
|| parse_mode == ParsingMode::Relaxed;
189+
if skippable {
186190
// Seek to the end, as we cannot gather anything else from the file
187191
data.seek(SeekFrom::End(0))?;
188192
return Ok(None);

0 commit comments

Comments
 (0)