11#![ no_main]
22
33use libfuzzer_sys:: fuzz_target;
4- use std:: io:: { Read , Seek , SeekFrom } ;
54use tikv_jemallocator:: Jemalloc ;
5+
6+ use std:: io:: prelude:: * ;
7+
68use zip:: read:: read_zipfile_from_stream;
9+ use zip:: unstable:: read:: streaming:: StreamingArchive ;
710
811const MAX_BYTES_TO_READ : u64 = 1 << 24 ;
912
@@ -19,13 +22,34 @@ fn decompress_all(data: &[u8]) -> Result<(), Box<dyn std::error::Error>> {
1922 std:: io:: copy ( & mut file, & mut std:: io:: sink ( ) ) ?;
2023 }
2124 let mut reader = zip. into_inner ( ) ;
22- reader. seek ( SeekFrom :: Start ( 0 ) ) ?;
25+ reader. rewind ( ) ?;
2326 while let Ok ( Some ( mut file) ) = read_zipfile_from_stream ( & mut reader) {
2427 std:: io:: copy ( & mut file, & mut std:: io:: sink ( ) ) ?;
2528 }
2629 Ok ( ( ) )
2730}
2831
32+ fn decompress_generic ( data : & [ u8 ] ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
33+ let reader = std:: io:: Cursor :: new ( data) ;
34+ let mut zip = zip:: ZipArchive :: new ( reader) ?;
35+
36+ for i in 0 ..zip. len ( ) {
37+ let mut file = zip. by_index_generic ( i) ?. take ( MAX_BYTES_TO_READ ) ;
38+ std:: io:: copy ( & mut file, & mut std:: io:: sink ( ) ) ?;
39+ }
40+
41+ let mut reader = zip. into_inner ( ) ;
42+ reader. rewind ( ) ?;
43+ let mut stream_zip = StreamingArchive :: new ( reader) ;
44+
45+ while let Some ( mut file) = stream_zip. next_entry ( ) ? {
46+ std:: io:: copy ( & mut file, & mut std:: io:: sink ( ) ) ?;
47+ }
48+ while let Some ( _) = stream_zip. next_metadata_entry ( ) ? { }
49+ Ok ( ( ) )
50+ }
51+
2952fuzz_target ! ( |data: & [ u8 ] | {
3053 let _ = decompress_all( data) ;
54+ let _ = decompress_generic( data) ;
3155} ) ;
0 commit comments