-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial fuzzing harness for animated images (#32)
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {}; | ||
} | ||
} | ||
} | ||
}); |