diff --git a/CHANGELOG.md b/CHANGELOG.md index cbbdfa36e..5a6e6833d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- **MusePack**: Fix potential panic when the beginning silence makes up the entire sample count ([PR](https://github.com/Serial-ATA/lofty-rs/pull/449)) + ## [0.21.1] - 2024-08-28 ### Changed diff --git a/lofty/src/musepack/sv8/properties.rs b/lofty/src/musepack/sv8/properties.rs index bf8639b86..c8a4b633b 100644 --- a/lofty/src/musepack/sv8/properties.rs +++ b/lofty/src/musepack/sv8/properties.rs @@ -278,6 +278,14 @@ pub(super) fn read( } let total_samples = sample_count - beginning_silence; + if total_samples == 0 { + log::warn!( + "Sample count (after removing beginning silence) is 0, unable to calculate duration \ + and bitrate" + ); + return Ok(properties); + } + let length = (total_samples * 1000).div_round(u64::from(sample_rate)); properties.duration = Duration::from_millis(length);