Bug fix: allow invalid compressed files, but verify length if decompression succeeds
This commit is contained in:
parent
026a49ffa7
commit
9113cb6b07
1 changed files with 7 additions and 1 deletions
|
@ -2,13 +2,19 @@
|
|||
use libfuzzer_sys::fuzz_target;
|
||||
use std::io::Read;
|
||||
|
||||
const MAX_BYTES_TO_READ: u64 = 1 << 24;
|
||||
|
||||
fn decompress_all(data: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let reader = std::io::Cursor::new(data);
|
||||
let mut zip = zip_next::ZipArchive::new(reader)?;
|
||||
|
||||
for i in 0..zip.len() {
|
||||
let file = zip.by_index(i)?;
|
||||
std::io::copy(&mut file.take(1 << 24), &mut std::io::sink())?;
|
||||
let expected_bytes = file.size().max(MAX_BYTES_TO_READ);
|
||||
let result = std::io::copy(&mut file.take(MAX_BYTES_TO_READ), &mut std::io::sink());
|
||||
if let Ok(bytes) = result {
|
||||
assert_eq!(expected_bytes, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue