Skip to content

Commit 15e893e

Browse files
committed
MP4: Fix panic on invalid data atom size
1 parent 3541fd7 commit 15e893e

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- **MP4**:
3030
- Fix panic when reading properties of a file with no timescale specified ([issue](https://github.com/Serial-ATA/lofty-rs/issues/418))
3131
- Fix panics when reading improperly sized freeform atom identifiers ([issue](https://github.com/Serial-ATA/lofty-rs/issues/425)) ([issue](https://github.com/Serial-ATA/lofty-rs/issues/426))
32+
- Fix panic when `data` atom length is less than 16 bytes ([issue](https://github.com/Serial-ATA/lofty-rs/issues/429))
3233
- **WAV**:
3334
- Fix panic when reading properties with large written bytes per second ([issue](https://github.com/Serial-ATA/lofty-rs/issues/420))
3435
- Fix panic when reading an improperly sized INFO LIST ([issue](https://github.com/Serial-ATA/lofty-rs/issues/427))

lofty/src/mp4/ilst/read.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ where
226226
break;
227227
};
228228

229+
if next_atom.len < 16 {
230+
log::warn!(
231+
"Expected data atom to be at least 16 bytes, got {}. Stopping",
232+
next_atom.len
233+
);
234+
if parsing_mode == ParsingMode::Strict {
235+
err!(BadAtom("Data atom is too small"))
236+
}
237+
238+
break;
239+
}
240+
229241
// We don't care about the version
230242
let _version = reader.read_u8()?;
231243

@@ -239,7 +251,6 @@ where
239251

240252
match next_atom.ident {
241253
DATA_ATOM_IDENT => {
242-
debug_assert!(next_atom.len >= 16);
243254
let content_len = (next_atom.len - 16) as usize;
244255
if content_len > 0 {
245256
let mut content = try_vec![0; content_len];

lofty/tests/fuzz/mp4file_read_from.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ fn panic2() {
2323
);
2424
let _ = Mp4File::read_from(&mut reader, ParseOptions::new());
2525
}
26+
27+
#[test]
28+
fn panic3() {
29+
let mut reader = crate::get_reader(
30+
"mp4file_read_from/steam_at_mention_IDX_60_RAND_135276517902742448802109.m4a",
31+
);
32+
let _ = Mp4File::read_from(&mut reader, ParseOptions::new());
33+
}

0 commit comments

Comments
 (0)