wav: Fix issue #174 and add regression test

This commit is contained in:
Uwe Klotz 2023-04-06 22:59:45 +02:00 committed by Alex
parent abbc484164
commit e3fa808d96
3 changed files with 23 additions and 8 deletions

View file

@ -182,15 +182,18 @@ pub(super) fn read_properties(
}
} else if stream_len > 0 && bytes_per_second > 0 {
let length = (u64::from(stream_len) * 1000) / u64::from(bytes_per_second);
if length == 0 {
(Duration::ZERO, 0, 0)
} else {
let overall_bitrate = ((file_length * 8) / length) as u32;
let audio_bitrate = (bytes_per_second * 8) / 1000;
let overall_bitrate = ((file_length * 8) / length) as u32;
let audio_bitrate = (bytes_per_second * 8) / 1000;
(
Duration::from_millis(length),
overall_bitrate,
audio_bitrate,
)
(
Duration::from_millis(length),
overall_bitrate,
audio_bitrate,
)
}
} else {
(Duration::ZERO, 0, 0)
};

View file

@ -70,3 +70,15 @@ fn remove_riff_info() {
TagType::RIFFInfo
);
}
#[test]
fn issue_174_divide_by_zero() {
let file = Probe::open(
"tests/files/assets/issue_174_waveformatextensible-ieeefloat-44100Hz-mono95060.wav",
)
.unwrap()
.read()
.unwrap();
assert_eq!(file.file_type(), FileType::WAV);
}