Skip to content

Commit

Permalink
AIFF: Fixed division by zero panic during property reading
Browse files Browse the repository at this point in the history
closes #56
  • Loading branch information
Serial-ATA committed Jun 21, 2022
1 parent 03276db commit f0ea177
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Ilst::track_number` has been moved to the `Accessor::track` implementation
- Renamed `Tag::get_texts` to `Tag::get_strings`

### Fixed
- **AIFF**: Fixed division by zero panic during property reading ([issue](https://github.com/Serial-ATA/lofty-rs/issues/56))

## [0.6.3] - 2022-05-18

### Added
Expand Down
8 changes: 4 additions & 4 deletions src/iff/aiff/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ pub(super) fn read_properties(
let sample_rate = float.round() as u32;

let (duration, overall_bitrate, audio_bitrate) = if sample_rate > 0 && sample_frames > 0 {
let length = (u64::from(sample_frames) * 1000) / u64::from(sample_rate);
let length = (u64::from(sample_frames) * 1000) as f64 / f64::from(sample_rate);

(
Duration::from_millis(length),
Some(((file_length * 8) / length) as u32),
Some((u64::from(stream_len * 8) / length) as u32),
Duration::from_millis(length as u64),
Some(((file_length as f64) * 8.0 / length + 0.5) as u32),
Some((f64::from(stream_len) * 8.0 / length + 0.5) as u32),
)
} else {
(Duration::ZERO, None, None)
Expand Down

0 comments on commit f0ea177

Please sign in to comment.