Skip to content

Commit 2a7c061

Browse files
committed
WAV: Fix panic on improperly sized INFO LISTs
1 parent dd9aa76 commit 2a7c061

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- **MP4**:
2929
- Fix panic when reading properties of a file with no timescale specified ([issue](https://github.com/Serial-ATA/lofty-rs/issues/418))
3030
- Fix panics when reading improperly sized freeform atom identifiers ([issue](https://github.com/Serial-ATA/lofty-rs/issues/425)) ([issue](https://github.com/Serial-ATA/lofty-rs/issues/426))
31-
- **WAV**: Fix panic when reading properties with large written bytes per second ([issue](https://github.com/Serial-ATA/lofty-rs/issues/420))
31+
- **WAV**:
32+
- Fix panic when reading properties with large written bytes per second ([issue](https://github.com/Serial-ATA/lofty-rs/issues/420))
33+
- Fix panic when reading an improperly sized INFO LIST ([issue](https://github.com/Serial-ATA/lofty-rs/issues/427))
3234
- **Vorbis**: Fix panic when reading properties of a file with large absolute granule positions ([issue](https://github.com/Serial-ATA/lofty-rs/issues/421))
3335
- **FLAC**: Fix panic when reading properties of a file with incorrect block sizes ([issue](https://github.com/Serial-ATA/lofty-rs/issues/422))
3436
- **AIFF**: Fix panic when reading properties of a file with invalid f80 sample rate ([issue](https://github.com/Serial-ATA/lofty-rs/issues/424))

lofty/src/iff/wav/read.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::config::ParseOptions;
55
use crate::error::Result;
66
use crate::id3::v2::tag::Id3v2Tag;
77
use crate::iff::chunk::Chunks;
8-
use crate::macros::decode_err;
8+
use crate::macros::{decode_err, err};
99

1010
use std::io::{Read, Seek, SeekFrom};
1111

@@ -74,12 +74,25 @@ where
7474
chunks.skip(data)?;
7575
},
7676
b"LIST" => {
77+
let mut size = chunks.size;
78+
if size < 4 {
79+
decode_err!(@BAIL Wav, "Invalid LIST chunk size");
80+
}
81+
7782
let mut list_type = [0; 4];
7883
data.read_exact(&mut list_type)?;
7984

85+
size -= 4;
86+
8087
match &list_type {
8188
b"INFO" if parse_options.read_tags => {
82-
let end = data.stream_position()? + u64::from(chunks.size - 4);
89+
// TODO: We already get the current position above, just keep it up to date and use it here
90+
// to avoid the seeks.
91+
let end = data.stream_position()? + u64::from(size);
92+
if end > file_len {
93+
err!(SizeMismatch);
94+
}
95+
8396
super::tag::read::parse_riff_info(data, &mut chunks, end, &mut riff_info)?;
8497
},
8598
_ => {
Binary file not shown.

lofty/tests/fuzz/wavfile_read_from.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ fn panic1() {
1414
crate::get_reader("wavfile_read_from/2_IDX_0_RAND_85629492689553753214598.wav");
1515
let _ = WavFile::read_from(&mut reader, ParseOptions::new());
1616
}
17+
18+
#[test]
19+
fn panic2() {
20+
let mut reader =
21+
crate::get_reader("wavfile_read_from/2_IDX_63_RAND_104275228651573584855676.wav");
22+
let _ = WavFile::read_from(&mut reader, ParseOptions::new());
23+
}

0 commit comments

Comments
 (0)