Skip to content

Commit

Permalink
MPC: Fix potential divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Aug 31, 2024
1 parent c4ddd53 commit e54a0ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lofty/src/musepack/sv8/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e54a0ab

Please sign in to comment.