Skip to content

Commit

Permalink
Add tests from fuzzing
Browse files Browse the repository at this point in the history
Add test from fuzzing samples in image-rs#28, image-rs#29 and image-rs#31
  • Loading branch information
birktj committed Feb 27, 2019
1 parent bd0d66c commit 95b153c
Show file tree
Hide file tree
Showing 77 changed files with 42 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/fuzz_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
extern crate tiff;

use tiff::{TiffResult, ColorType};
use tiff::decoder::{Decoder, DecodingResult, ifd::Tag, ifd::Value};

use std::fs::File;

fn test_directory<F: Fn(File) -> bool>(path: &str, f: F) {
for entry in std::fs::read_dir(path).unwrap() {
let file = File::open(entry.unwrap().path()).unwrap();
assert!(f(file));
}
}

fn decode_tiff(file: File) -> TiffResult<()> {
let mut decoder = Decoder::new(file)?;
decoder.read_image()?;
Ok(())
}

#[test]
fn oor_panic() {
test_directory("./tests/fuzz_images/oor_panic", |file| {
decode_tiff(file).ok();
true
});
}

#[test]
fn oom_crash() {
test_directory("./tests/fuzz_images/oom_crash", |file| {
decode_tiff(file).is_err()
});
}

#[test]
fn inf_loop() {
test_directory("./tests/fuzz_images/inf_loop", |file| {
decode_tiff(file).ok();
true
});
}

0 comments on commit 95b153c

Please sign in to comment.