Skip to content

Commit

Permalink
Initial fuzzing harness for animated images (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel authored Dec 28, 2023
1 parent cc5ec05 commit 67a0f4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ name = "decode_still"
path = "fuzz_targets/decode_still.rs"
test = false
doc = false


[[bin]]
name = "decode_animated"
path = "fuzz_targets/decode_animated.rs"
test = false
doc = false
19 changes: 19 additions & 0 deletions fuzz/fuzz_targets/decode_animated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use std::io::Cursor;

fuzz_target!(|input: &[u8]| {
let decoder = webp::WebPDecoder::new(Cursor::new(input));
if let Ok(mut decoder) = decoder {
let (width, height) = decoder.dimensions();
let bytes_per_pixel = if decoder.has_alpha() { 4 } else { 3 };
let total_bytes = width as usize * height as usize * bytes_per_pixel;
if total_bytes <= 1024 * 1024 * 1024 {
if decoder.has_animation() {
let mut data = vec![0; total_bytes];
while let Ok(_delay) = decoder.read_frame(&mut data) {};
}
}
}
});

0 comments on commit 67a0f4e

Please sign in to comment.