forked from image-rs/image-png
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
32 lines (25 loc) · 845 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extern crate afl;
extern crate png;
// detect_odr_violation=0 is for https://github.com/rust-lang/rust/issues/41807
const ASAN_DEFAULT_OPTIONS: &'static [u8] = b"detect_odr_violation=0\0";
#[no_mangle]
pub extern "C" fn __asan_default_options() -> *const u8 {
ASAN_DEFAULT_OPTIONS as *const [u8] as *const u8
}
#[inline(always)]
fn png_decode(data: &[u8]) -> Result<(png::OutputInfo, Vec<u8>), ()> {
let decoder = png::Decoder::new(data);
let (info, mut reader) = decoder.read_info().map_err(|_| ())?;
if info.buffer_size() > 5_000_000 {
return Err(());
}
let mut img_data = Vec::with_capacity(info.buffer_size());
reader.next_frame(&mut img_data).map_err(|_| ())?;
Ok((info, img_data))
}
fn main() {
afl::fuzz(|data| {
//afl::read_stdio_bytes(|data| {
png_decode(&data);
});
}