From e54a0abd00efc23d3ea07626ccb7df282ccc5036 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 31 Aug 2024 00:08:49 -0400 Subject: [PATCH] MPC: Fix potential divide by zero --- CHANGELOG.md | 3 +++ lofty/src/musepack/sv8/properties.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbbdfa36..5a6e6833 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 bf8639b8..c8a4b633 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);