Skip to content

Commit 35eb578

Browse files
committed
MPEG: Fix potential panic in stream length calculation
1 parent 013b17d commit 35eb578

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5959
- **WavPack***: Fix panic when encountering wrongly sized blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/472)) ([issue](https://github.com/Serial-ATA/lofty-rs/issues/480))
6060
- **WavPack***: Fix panic when encountering zero-sized blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/473))
6161
- **MPEG**: Fix panic when APE tags are incorrectly sized ([issue](https://github.com/Serial-ATA/lofty-rs/issues/474))
62+
- **MPEG**: Fix panic when calculating the stream length for files with improperly sized frames ([issue](https://github.com/Serial-ATA/lofty-rs/issues/487))
6263
- **ID3v2**: Fix panic when parsing non-ASCII `TDAT` and `TIME` frames in `TDRC` conversion ([issue](https://github.com/Serial-ATA/lofty-rs/issues/477))
6364
- **APE**: Fix panic when parsing incorrectly sized header APE tags ([issue](https://github.com/Serial-ATA/lofty-rs/issues/481))
6465

lofty/src/mpeg/properties.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ where
212212
return Ok(());
213213
};
214214

215-
let stream_len = (last_frame_offset + u64::from(last_frame_header.len)) - first_frame_offset;
215+
let stream_end = last_frame_offset + u64::from(last_frame_header.len);
216+
if stream_end < first_frame_offset {
217+
// Something is incredibly wrong with this file, just give up
218+
return Ok(());
219+
}
220+
221+
let stream_len = stream_end - first_frame_offset;
216222
if !is_cbr {
217223
log::debug!("MPEG: VBR detected");
218224

lofty/tests/fuzz/mpegfile_read_from.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ fn crash4() {
3333
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
3434
}
3535

36+
#[test_log::test]
37+
fn crash5() {
38+
let mut reader =
39+
get_reader("mpegfile_read_from/crash-625fdf469a07ca27b291122f8f95f6fce4458ad5_minimized");
40+
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
41+
}
42+
3643
#[test_log::test]
3744
fn oom1() {
3845
oom_test::<MpegFile>("mpegfile_read_from/oom-f8730cbfa5682ab12343ccb70de9b71a061ef4d0");

0 commit comments

Comments
 (0)