Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,15 +599,11 @@ impl<R> WavReader<R>

let num_samples = data_len / spec_ex.bytes_per_sample as u32;

// It could be that num_samples * bytes_per_sample < data_len.
// If data_len is not a multiple of bytes_per_sample, there is some
// trailing data. Either somebody is playing some steganography game,
// but more likely something is very wrong, and we should refuse to
// decode the file, as it is invalid.
if num_samples * spec_ex.bytes_per_sample as u32 != data_len {
let msg = "data chunk length is not a multiple of sample size";
return Err(Error::FormatError(msg));
}
// If data_len is not a multiple of bytes_per_sample, the trailing
// partial sample byte(s) are silently discarded. The integer division
// above already truncates to the last complete sample frame.
// This tolerates WAV files where the last byte of a multi-byte sample
// was lost (e.g., truncated file transfers).

// The number of samples must be a multiple of the number of channels,
// otherwise the last inter-channel sample would not have data for all
Expand Down