Skip to content

Commit

Permalink
Initial fuzzing support, still images only (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel authored Dec 19, 2023
1 parent 944a249 commit 907aa34
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
144 changes: 144 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "webp-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.webp]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "decode_still"
path = "fuzz_targets/decode_still.rs"
test = false
doc = false
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/decode_still.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![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 mut data = vec![0; width as usize * height as usize * bytes_per_pixel];
let _ = decoder.read_image(&mut data);
}
});

0 comments on commit 907aa34

Please sign in to comment.