WAV: Fix potential overflow in bit depth calculation

This commit is contained in:
Serial 2024-10-29 20:31:36 -04:00 committed by Alex
parent d6e5553732
commit f86f1e017a
3 changed files with 7 additions and 1 deletions

View file

@ -209,7 +209,7 @@ pub(super) fn read_properties(
.. ..
}) if valid_bits_per_sample > 0 => bit_depth = valid_bits_per_sample as u8, }) if valid_bits_per_sample > 0 => bit_depth = valid_bits_per_sample as u8,
_ if bits_per_sample > 0 => bit_depth = bits_per_sample as u8, _ if bits_per_sample > 0 => bit_depth = bits_per_sample as u8,
_ => bit_depth = (bytes_per_sample * 8) as u8, _ => bit_depth = bytes_per_sample.saturating_mul(8) as u8,
}; };
let channel_mask = extensible_info.map(|info| info.channel_mask); let channel_mask = extensible_info.map(|info| info.channel_mask);

Binary file not shown.

View file

@ -28,3 +28,9 @@ fn panic3() {
crate::get_reader("wavfile_read_from/2_IDX_34_RAND_128635499166458268533001.wav"); crate::get_reader("wavfile_read_from/2_IDX_34_RAND_128635499166458268533001.wav");
let _ = WavFile::read_from(&mut reader, ParseOptions::new()); let _ = WavFile::read_from(&mut reader, ParseOptions::new());
} }
#[test_log::test]
fn panic4() {
let mut reader = crate::get_reader("wavfile_read_from/aa");
let _ = WavFile::read_from(&mut reader, ParseOptions::new());
}