Skip to content

Commit 37fdc65

Browse files
committed
MP4: Fix division by zero panic
1 parent 61adb2a commit 37fdc65

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525

2626
### Fixed
2727
- **Fuzzing** (Thanks [@qarmin](https://github.com/qarmin)!) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/TODO)):
28+
- **MP4**: Fix panic when reading properties of a file with no timescale specified ([issue](https://github.com/Serial-ATA/lofty-rs/issues/418))
2829
- **WAV**: Fix panic when reading properties with large written bytes per second ([issue](https://github.com/Serial-ATA/lofty-rs/issues/420))
2930
- **Vorbis**: Fix panic when reading properties of a file with large absolute granule positions ([issue](https://github.com/Serial-ATA/lofty-rs/issues/421))
3031
- **FLAC**: Fix panic when reading properties of a file with incorrect block sizes ([issue](https://github.com/Serial-ATA/lofty-rs/issues/422))

lofty/src/mp4/properties.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,13 @@ where
510510
}
511511
}
512512

513+
// TODO: We need to eventually calculate the duration from the stts atom
514+
// if there is no timescale available.
513515
let duration_millis = properties.duration.as_millis();
516+
if duration_millis == 0 {
517+
log::warn!("Duration is 0, unable to calculate bitrate");
518+
return Ok(properties);
519+
}
514520

515521
let overall_bitrate = u128::from(file_length * 8) / duration_millis;
516522
properties.overall_bitrate = overall_bitrate as u32;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
use crate::oom_test;
2+
use lofty::config::ParseOptions;
3+
use lofty::file::AudioFile;
24
use lofty::mp4::Mp4File;
35

46
#[test]
57
fn oom1() {
68
oom_test::<Mp4File>("mp4file_read_from/oom-db2665d79ec9c045bdb9c1e9a3d0c93e7e59393e");
79
}
10+
11+
#[test]
12+
fn panic1() {
13+
let mut reader = crate::get_reader(
14+
"mp4file_read_from/steam_at_mention_IDX_34_RAND_4491956654166691611931.m4a",
15+
);
16+
let _ = Mp4File::read_from(&mut reader, ParseOptions::new());
17+
}

0 commit comments

Comments
 (0)