forked from image-rs/image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3c7d5c
commit a6ae674
Showing
5 changed files
with
72 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Fuzzing harnesses | ||
|
||
This is intended for integration fuzzing and those decoders that do not yet | ||
live in their own crate. `image-png` for example has their own fuzzing targets. | ||
|
||
## Using the fuzzer | ||
|
||
> $ cargo install afl | ||
> $ cargo afl build | ||
> $ cargo afl fuzz -i ./in/<format> -o ./out/<format> ./target/release/fuzzer_script_<format> | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
#![no_main] | ||
#[macro_use] extern crate libfuzzer_sys; | ||
extern crate afl; | ||
extern crate image; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let _ = image::load_from_memory_with_format(data, image::ImageFormat::PNM); | ||
}); | ||
use image::ImageDecoder; | ||
|
||
#[inline(always)] | ||
fn pnm_decode(data: &[u8]) -> image::ImageResult<Vec<u8>> { | ||
let decoder = image::pnm::PNMDecoder::new(data)?; | ||
let (width, height) = decoder.dimensions(); | ||
|
||
if width.saturating_mul(height) > 4_000_000 { | ||
return Err(image::ImageError::DimensionError); | ||
} | ||
|
||
decoder.read_image() | ||
} | ||
|
||
fn main() { | ||
afl::fuzz(|data| { | ||
let _ = pnm_decode(data); | ||
}); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
P7 | ||
WIDTH 1 | ||
HEIGHT 1 | ||
TUPLTYPE GRAYSCALE | ||
ENDHDR | ||
H |