Skip to content

Commit

Permalink
Fix fuzz_webp_no_panic test
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia committed Sep 19, 2023
1 parent 9a8591a commit e831f8b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/codecs/webp/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,24 @@ mod native_tests {

fn fuzz_webp_no_panic(data: Vec<u8>, width: u8, height: u8, quality: u8) -> bool {
// Check random (usually invalid) parameters do not panic.

if data.len() < width as usize * height as usize * 4 {
return true;
}

let mut buffer = Vec::<u8>::new();
for color in [ColorType::Rgb8, ColorType::Rgba8] {
for webp_quality in [WebPQuality::lossless(), #[allow(deprecated)] WebPQuality::lossy(quality)] {
buffer.clear();
#[allow(deprecated)]
let encoder = WebPEncoder::new_with_quality(&mut buffer, webp_quality);
// Ignore errors.
let _ = encoder
.write_image(&data, width as u32, height as u32, color);
let _ = encoder.write_image(
&data[..width as usize * height as usize * color.bytes_per_pixel() as usize],
width as u32,
height as u32,
color,
);
}
}
true
Expand Down

0 comments on commit e831f8b

Please sign in to comment.