Skip to content

Commit 831ac30

Browse files
committed
MPEG: Verify the size of APE tags
1 parent 8ad3aeb commit 831ac30

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lofty/src/mpeg/read.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ where
163163

164164
// Seek back to the start of the tag
165165
let pos = reader.stream_position()?;
166-
reader.seek(SeekFrom::Start(pos - u64::from(header.size)))?;
166+
let Some(start_of_tag) = pos.checked_sub(u64::from(header.size)) else {
167+
err!(SizeMismatch);
168+
};
169+
170+
reader.seek(SeekFrom::Start(start_of_tag))?;
167171
},
168172
_ => {
169173
// Correct the position (APE header - Preamble)
Binary file not shown.

lofty/tests/fuzz/mpegfile_read_from.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ fn crash2() {
1919
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
2020
}
2121

22+
#[test_log::test]
23+
fn crash3() {
24+
let mut reader =
25+
get_reader("mpegfile_read_from/crash-7b5eb183cc14faf3ecc93bdf4a5e30b05f7a537d_minimized");
26+
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
27+
}
28+
2229
#[test_log::test]
2330
fn oom1() {
2431
oom_test::<MpegFile>("mpegfile_read_from/oom-f8730cbfa5682ab12343ccb70de9b71a061ef4d0");

0 commit comments

Comments
 (0)