Skip to content

Commit e3fa808

Browse files
uklotzdeSerial-ATA
authored andcommitted
wav: Fix issue #174 and add regression test
1 parent abbc484 commit e3fa808

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/iff/wav/properties.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,18 @@ pub(super) fn read_properties(
182182
}
183183
} else if stream_len > 0 && bytes_per_second > 0 {
184184
let length = (u64::from(stream_len) * 1000) / u64::from(bytes_per_second);
185+
if length == 0 {
186+
(Duration::ZERO, 0, 0)
187+
} else {
188+
let overall_bitrate = ((file_length * 8) / length) as u32;
189+
let audio_bitrate = (bytes_per_second * 8) / 1000;
185190

186-
let overall_bitrate = ((file_length * 8) / length) as u32;
187-
let audio_bitrate = (bytes_per_second * 8) / 1000;
188-
189-
(
190-
Duration::from_millis(length),
191-
overall_bitrate,
192-
audio_bitrate,
193-
)
191+
(
192+
Duration::from_millis(length),
193+
overall_bitrate,
194+
audio_bitrate,
195+
)
196+
}
194197
} else {
195198
(Duration::ZERO, 0, 0)
196199
};
Binary file not shown.

tests/files/wav.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,15 @@ fn remove_riff_info() {
7070
TagType::RIFFInfo
7171
);
7272
}
73+
74+
#[test]
75+
fn issue_174_divide_by_zero() {
76+
let file = Probe::open(
77+
"tests/files/assets/issue_174_waveformatextensible-ieeefloat-44100Hz-mono95060.wav",
78+
)
79+
.unwrap()
80+
.read()
81+
.unwrap();
82+
83+
assert_eq!(file.file_type(), FileType::WAV);
84+
}

0 commit comments

Comments
 (0)