Skip to content

Commit

Permalink
Merge pull request #43 from dgriffen/invalid-images
Browse files Browse the repository at this point in the history
Invalid images
  • Loading branch information
ZoeyR authored Jul 28, 2018
2 parents d42d7bf + 5aebdaf commit 328a752
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion flif-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ enum Command {
#[structopt(name = "decode")]
Decode {
#[structopt(
short = "i", long = "identify", help = "don't decode, just identify the input FLIF"
short = "i",
long = "identify",
help = "don't decode, just identify the input FLIF"
)]
identify: bool,
#[structopt(name = "INPUT", help = "Input file")]
Expand Down
6 changes: 3 additions & 3 deletions flif/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub enum Channel {

#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum ColorSpace {
Monochrome,
RGB,
RGBA,
Monochrome = 1,
RGB = 3,
RGBA = 4,
}

pub type Pixel = ChannelSet<ColorValue>;
Expand Down
4 changes: 2 additions & 2 deletions flif/src/components/transformations/channel_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl ChannelCompact {
let t_range = transformation.range(c);
t.ranges[c].max = rac.read_near_zero(0, t_range.max - t_range.min, &mut context)?;
let mut min = t_range.min;
for i in 0..t.ranges[c].max {
for i in 0..t.ranges[c].max + 1 {
t.decompacted[c].push(
min + rac.read_near_zero(
0,
t_range.max - (min + (t.ranges[c].max - i)),
&mut context,
)?,
);
min = t.decompacted[c][i as usize];
min = t.decompacted[c][i as usize] + 1;
}
}

Expand Down
27 changes: 27 additions & 0 deletions flif/tests/channel_compact.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate flif;

use std::fs::File;
use std::io::BufReader;

use flif::components::Transformation;
use flif::Decoder;

#[test]
fn invalid_tree() {
let file = BufReader::new(File::open("../resources/invalid_tree.flif").unwrap());
let image = Decoder::new(file).unwrap();
let info = image.info();

let expected = vec![Transformation::ChannelCompact];
assert_eq!(expected, info.second_header.transformations);
}

#[test]
fn invalid_transform() {
let file = BufReader::new(File::open("../resources/invalid_tid.flif").unwrap());
let image = Decoder::new(file).unwrap();
let info = image.info();

let expected = vec![Transformation::ChannelCompact];
assert_eq!(expected, info.second_header.transformations);
}
Binary file added resources/invalid_tid.flif
Binary file not shown.
Binary file added resources/invalid_tree.flif
Binary file not shown.

0 comments on commit 328a752

Please sign in to comment.