Skip to content

Commit a7ff357

Browse files
committed
WV: Fuzzing fixes
1 parent dd4e926 commit a7ff357

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5959
- **WavPack***: Fix panic when encountering wrongly sized blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/472)) ([issue](https://github.com/Serial-ATA/lofty-rs/issues/480))
6060
- **WavPack***: Fix panic when encountering zero-sized blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/473))
6161
- **WavPack**: Verify the size of non-standard sample rate blocks ([issue](https://github.com/Serial-ATA/lofty-rs/issues/488))
62+
- **WavPack**: Fix potential overflow in bit depth calculation ([issue](https://github.com/Serial-ATA/lofty-rs/issues/491))
6263
- **MPEG**: Fix panic when APE tags are incorrectly sized ([issue](https://github.com/Serial-ATA/lofty-rs/issues/474))
6364
- **MPEG**: Fix panic when calculating the stream length for files with improperly sized frames ([issue](https://github.com/Serial-ATA/lofty-rs/issues/487))
6465
- **ID3v2**: Fix panic when parsing non-ASCII `TDAT` and `TIME` frames in `TDRC` conversion ([issue](https://github.com/Serial-ATA/lofty-rs/issues/477))

lofty/src/wavpack/properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ where
187187
}
188188

189189
total_samples = block_header.total_samples;
190-
properties.bit_depth = ((((flags & BYTES_PER_SAMPLE_MASK) + 1) * 8) - ((flags & BIT_DEPTH_SHIFT_MASK) >> BIT_DEPTH_SHL)) as u8;
190+
properties.bit_depth = (((flags & BYTES_PER_SAMPLE_MASK) + 1) * 8).saturating_sub((flags & BIT_DEPTH_SHIFT_MASK) >> BIT_DEPTH_SHL) as u8;
191191

192192
properties.version = block_header.version;
193193
properties.lossless = flags & FLAG_HYBRID_COMPRESSION == 0;
@@ -414,6 +414,10 @@ fn get_extended_meta_info(
414414
}
415415

416416
// Skip over any remaining block size
417+
if (size as usize) > reader.len() {
418+
err!(SizeMismatch);
419+
}
420+
417421
let (_, rem) = reader.split_at(size as usize);
418422
*reader = rem;
419423

lofty/tests/fuzz/wavpackfile_read_from.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,19 @@ fn panic5() {
120120
);
121121
let _ = WavPackFile::read_from(&mut reader, ParseOptions::default());
122122
}
123+
124+
#[test_log::test]
125+
fn panic6() {
126+
let mut reader = crate::get_reader(
127+
"wavpackfile_read_from/crash-68a2215c732ecb202998d3bd8b0de932e5e0301d_minimized",
128+
);
129+
let _ = WavPackFile::read_from(&mut reader, ParseOptions::default());
130+
}
131+
132+
#[test_log::test]
133+
fn panic7() {
134+
let mut reader = crate::get_reader(
135+
"wavpackfile_read_from/crash-b583ce7029fc17100e2aabfa4679865a2a5fd9a4_minimized",
136+
);
137+
let _ = WavPackFile::read_from(&mut reader, ParseOptions::default());
138+
}

0 commit comments

Comments
 (0)