Skip to content

Commit

Permalink
Merge pull request #412 from whtsht/master
Browse files Browse the repository at this point in the history
Fixed `cargo afl build` compile error
  • Loading branch information
fintelia authored Sep 24, 2023
2 parents e11786e + b6a4f59 commit f10238a
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions png-afl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@

#![forbid(unsafe_code)]

#[macro_use]
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 {
let mut reader = decoder.read_info().map_err(|_| ())?;

let buffer_size = reader.output_buffer_size();
if buffer_size > 5_000_000 {
return Err(());
}

let mut img_data = vec![0u8; info.buffer_size()];
reader.next_frame(&mut img_data).map_err(|_| ())?;
let mut img_data = vec![0u8; buffer_size];
let info = reader.next_frame(&mut img_data).map_err(|_| ())?;

Ok((info, img_data))
}
Expand Down

0 comments on commit f10238a

Please sign in to comment.