forked from zip-rs/zip-old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_read.rs
More file actions
executable file
·47 lines (36 loc) · 1.22 KB
/
Copy pathfuzz_read.rs
File metadata and controls
executable file
·47 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_main]
use libfuzzer_sys::fuzz_target;
use std::io::{Read, Seek, SeekFrom};
use tikv_jemallocator::Jemalloc;
use zip::unstable::{
read::streaming::{StreamingArchive, StreamingZipEntry, ZipStreamFileMetadata},
stream::ZipStreamVisitor,
};
const MAX_BYTES_TO_READ: u64 = 1 << 24;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
fn decompress_all(data: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
let reader = std::io::Cursor::new(data);
let mut zip = zip::ZipArchive::new(reader)?;
for i in 0..zip.len() {
let mut file = zip.by_index(i)?.take(MAX_BYTES_TO_READ);
std::io::copy(&mut file, &mut std::io::sink())?;
}
let mut reader = zip.into_inner();
reader.rewind()?;
struct V;
impl ZipStreamVisitor for V {
fn visit_file(&mut self, file: &mut StreamingZipEntry<impl Read>) -> ZipResult<()> {
std::io::copy(&mut file, &mut std::io::sink())?
}
fn visit_additional_metadata(&mut self, metadata: &ZipStreamFileMetadata) -> ZipResult<()> {
Ok(())
}
}
let archive = StreamingArchive::new(reader)?;
archive.visit(&mut V)?;
Ok(())
}
fuzz_target!(|data: &[u8]| {
let _ = decompress_all(data);
});