Skip to content

Commit

Permalink
make sure inflate buffer is big enough
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jan 16, 2024
1 parent f2f0c23 commit 7d8b972
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion fuzz/fuzz_targets/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fuzz_target!(|input: (Level, Length)| {

assert_eq!(&deflated_rs, &deflated_ng);

match zlib::uncompress_help(&deflated_ng) {
match uncompress_help_ng(&deflated_ng) {
Err(err) => {
let raw_path = std::env::temp_dir().join("failed-inflate-raw.dat");
std::fs::write(&raw_path, &data).unwrap();
Expand All @@ -72,3 +72,24 @@ fuzz_target!(|input: (Level, Length)| {
}
}
});

#[allow(unused)]
fn uncompress_help_ng(input: &[u8]) -> Result<Vec<u8>, ReturnCode> {
let mut dest_vec = vec![0u8; BYTES.len()];

let mut dest_len = dest_vec.len();
let dest = dest_vec.as_mut_ptr();

let source = input.as_ptr();
let source_len = input.len();

let err = unsafe { libz_ng_sys::uncompress(dest, &mut dest_len, source, source_len) };

if err != 0 {
Err(ReturnCode::from(err))
} else {
dest_vec.truncate(dest_len);

Ok(dest_vec)
}
}

0 comments on commit 7d8b972

Please sign in to comment.