2021-11-30 16:21:03 +00:00
|
|
|
#![no_main]
|
|
|
|
use libfuzzer_sys::fuzz_target;
|
|
|
|
|
2022-01-06 00:59:32 +00:00
|
|
|
use qoi::{encode_size_limit, encode_to_vec};
|
2022-01-03 18:40:24 +00:00
|
|
|
|
2021-11-30 16:21:03 +00:00
|
|
|
fuzz_target!(|input: (bool, u8, &[u8])| {
|
|
|
|
let (is_4, w_frac, data) = input;
|
|
|
|
let channels = if is_4 { 4 } else { 3 };
|
|
|
|
let size = data.len();
|
|
|
|
let n_pixels = size / channels as usize;
|
|
|
|
let (w, h) = if n_pixels == 0 {
|
|
|
|
(0, 0)
|
|
|
|
} else {
|
|
|
|
let w = ((n_pixels * (1 + w_frac as usize)) / 256).max(1);
|
|
|
|
let h = n_pixels / w;
|
|
|
|
(w, h)
|
|
|
|
};
|
2022-01-03 18:40:24 +00:00
|
|
|
let out = encode_to_vec(&data[..(w * h * channels as usize)], w as u32, h as u32);
|
2021-11-30 16:21:03 +00:00
|
|
|
if w * h != 0 {
|
|
|
|
let out = out.unwrap();
|
2022-01-03 18:40:24 +00:00
|
|
|
assert!(out.len() <= encode_size_limit(w as u32, h as u32, channels));
|
2021-11-30 16:21:03 +00:00
|
|
|
} else {
|
|
|
|
assert!(out.is_err());
|
|
|
|
}
|
|
|
|
});
|