Skip to content

Commit 849c614

Browse files
committed
feed the fuzzer chunked input
1 parent eda5db8 commit 849c614

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

fuzz/fuzz_targets/uncompress.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,21 @@ fn run(input: &[u8]) -> Corpus {
7676
let input_len: u64 = input.len().try_into().unwrap();
7777
stream.next_out = output.as_mut_ptr();
7878
stream.avail_out = output.len().try_into().unwrap();
79-
stream.next_in = input.as_ptr();
80-
stream.avail_in = input.len().try_into().unwrap();
8179

82-
while input_len.checked_sub(stream.total_in).unwrap() > 0 {
83-
let err = unsafe { inflate(&mut stream, InflateFlush::Finish as _) };
80+
let chunk_size = 64;
81+
for chunk in input.chunks(chunk_size) {
82+
stream.next_in = chunk.as_ptr() as *mut u8;
83+
stream.avail_in = chunk.len() as _;
84+
85+
let err = unsafe { inflate(&mut stream, InflateFlush::NoFlush as _) };
8486
match ReturnCode::from(err) {
8587
ReturnCode::StreamEnd => {
8688
break;
8789
}
88-
ReturnCode::BufError | ReturnCode::Ok => {
90+
ReturnCode::Ok => {
91+
continue;
92+
}
93+
ReturnCode::BufError => {
8994
let add_space: u32 = Ord::max(1024, output.len().try_into().unwrap());
9095
output.resize(output.len() + add_space as usize, 0);
9196

0 commit comments

Comments
 (0)