Skip to content

Commit e54a0ab

Browse files
committed
MPC: Fix potential divide by zero
1 parent c4ddd53 commit e54a0ab

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- **MusePack**: Fix potential panic when the beginning silence makes up the entire sample count ([PR](https://github.com/Serial-ATA/lofty-rs/pull/449))
11+
912
## [0.21.1] - 2024-08-28
1013

1114
### Changed

lofty/src/musepack/sv8/properties.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ pub(super) fn read(
278278
}
279279

280280
let total_samples = sample_count - beginning_silence;
281+
if total_samples == 0 {
282+
log::warn!(
283+
"Sample count (after removing beginning silence) is 0, unable to calculate duration \
284+
and bitrate"
285+
);
286+
return Ok(properties);
287+
}
288+
281289
let length = (total_samples * 1000).div_round(u64::from(sample_rate));
282290

283291
properties.duration = Duration::from_millis(length);

0 commit comments

Comments
 (0)