From 15e893e26829e20dc101a94800a2fdb46c447f18 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Mon, 22 Jul 2024 12:44:16 -0400 Subject: [PATCH] MP4: Fix panic on invalid `data` atom size --- CHANGELOG.md | 1 + lofty/src/mp4/ilst/read.rs | 13 ++++++++++++- ...tion_IDX_60_RAND_135276517902742448802109.m4a | Bin 0 -> 3369 bytes lofty/tests/fuzz/mp4file_read_from.rs | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 lofty/tests/fuzz/assets/mp4file_read_from/steam_at_mention_IDX_60_RAND_135276517902742448802109.m4a diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b0bb00d..54b25f9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **MP4**: - Fix panic when reading properties of a file with no timescale specified ([issue](https://github.com/Serial-ATA/lofty-rs/issues/418)) - 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)) + - Fix panic when `data` atom length is less than 16 bytes ([issue](https://github.com/Serial-ATA/lofty-rs/issues/429)) - **WAV**: - Fix panic when reading properties with large written bytes per second ([issue](https://github.com/Serial-ATA/lofty-rs/issues/420)) - Fix panic when reading an improperly sized INFO LIST ([issue](https://github.com/Serial-ATA/lofty-rs/issues/427)) diff --git a/lofty/src/mp4/ilst/read.rs b/lofty/src/mp4/ilst/read.rs index 914f17e6..09623e1c 100644 --- a/lofty/src/mp4/ilst/read.rs +++ b/lofty/src/mp4/ilst/read.rs @@ -226,6 +226,18 @@ where break; }; + if next_atom.len < 16 { + log::warn!( + "Expected data atom to be at least 16 bytes, got {}. Stopping", + next_atom.len + ); + if parsing_mode == ParsingMode::Strict { + err!(BadAtom("Data atom is too small")) + } + + break; + } + // We don't care about the version let _version = reader.read_u8()?; @@ -239,7 +251,6 @@ where match next_atom.ident { DATA_ATOM_IDENT => { - debug_assert!(next_atom.len >= 16); let content_len = (next_atom.len - 16) as usize; if content_len > 0 { let mut content = try_vec![0; content_len]; diff --git a/lofty/tests/fuzz/assets/mp4file_read_from/steam_at_mention_IDX_60_RAND_135276517902742448802109.m4a b/lofty/tests/fuzz/assets/mp4file_read_from/steam_at_mention_IDX_60_RAND_135276517902742448802109.m4a new file mode 100755 index 0000000000000000000000000000000000000000..c7a9b7509c79d40d1a28862dea815189d31c1d87 GIT binary patch literal 3369 zcmeHGJ8KkC6h1R~tWQWnLJ|#T2ns25-R#aLDdXnRMS~A)M3~G>Hfwfv#+kb-Dv}6V z1hf?t1PNFKg|rqH78VvF(Z)ZZ5U{ndNa1&8?y!%fh}LtMkMrGg?z!jQ@6IJ6ZAskq z=Jg92!Pq;Vo-GBg!(*c3-Hz+lK*~;S+2Y7|ef<-I=!VHWcfDd*?5n~s(x9ExUv<9#WHv?5J9MJ6sPOB z1>PN7{ah+_ae#G)3R z0uYsHdSom@YgU&d!QwHi*oZkfFV534`eHu4A(gt?38B zPvsk)$5$HJ8FckZy2R3M8B7C<@^96)9=oJkQY)|5Z za6H~>PiqB@ZVHz(T4Sry)oR5Kw6Sb@BCV$