Skip to content

Commit

Permalink
Return an error when an APNG header is encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
emielbeinema committed Sep 30, 2017
1 parent 2b60d3a commit b417e2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ impl PngData {
};
if header.0 == "IDAT" {
idat_headers.extend(header.1);
} else if header.0 == "acTL" {
return Err(PngError::new("APNG files are not (yet) supported"));
} else {
aux_headers.insert(header.0, header.1);
}
Expand Down
Binary file added tests/files/apng_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ fn optimize_from_memory_corrupted() {
assert!(result.is_err());
}

#[test]
fn optimize_from_memory_apng() {
let mut in_file = File::open("tests/files/apng_file.png").unwrap();
let mut in_file_buf: Vec<u8> = Vec::new();
in_file.read_to_end(&mut in_file_buf).unwrap();

let mut opts: oxipng::Options = Default::default();
opts.verbosity = Some(1);

let result = oxipng::optimize_from_memory(&in_file_buf, &opts);
assert!(result.is_err());
}

#[test]
fn optimize() {
let mut opts: oxipng::Options = Default::default();
Expand All @@ -48,3 +61,12 @@ fn optimize_corrupted() {
let result = oxipng::optimize(Path::new("tests/files/corrupted_header.png"), &opts);
assert!(result.is_err());
}

#[test]
fn optimize_apng() {
let mut opts: oxipng::Options = Default::default();
opts.verbosity = Some(1);

let result = oxipng::optimize(Path::new("tests/files/apng_file.png"), &opts);
assert!(result.is_err());
}

0 comments on commit b417e2b

Please sign in to comment.