Skip to content

Commit

Permalink
Limit max memory allocation by fuzz target (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia authored Dec 26, 2023
1 parent cfd582c commit bb34e55
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fuzz/fuzz_targets/decode_still.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ fuzz_target!(|input: &[u8]| {
if let Ok(mut decoder) = decoder {
let (width, height) = decoder.dimensions();
let bytes_per_pixel = if decoder.has_alpha() { 4 } else { 3 };
let mut data = vec![0; width as usize * height as usize * bytes_per_pixel];
let _ = decoder.read_image(&mut data);
let total_bytes = width as usize * height as usize * bytes_per_pixel;
if total_bytes <= 1024 * 1024 * 1024 {
let mut data = vec![0; total_bytes];
let _ = decoder.read_image(&mut data);
}
}
});

0 comments on commit bb34e55

Please sign in to comment.