diff options
-rw-r--r-- | gifed/src/block/indexedimage.rs | 9 | ||||
-rw-r--r-- | gifed/src/reader/mod.rs | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/gifed/src/block/indexedimage.rs b/gifed/src/block/indexedimage.rs index 8742901..1868382 100644 --- a/gifed/src/block/indexedimage.rs +++ b/gifed/src/block/indexedimage.rs @@ -1,4 +1,4 @@ -use weezl::encode::Encoder; +use weezl::{encode::Encoder, LzwError}; use crate::{reader::DecodeError, EncodeError}; @@ -129,8 +129,11 @@ impl CompressedImage { let data: Vec<u8> = blocks.into_iter().map(<_>::into_iter).flatten().collect(); //TODO: remove unwrap - let mut decompressor = weezl::decode::Decoder::new(weezl::BitOrder::Lsb, lzw_code_size); - let indicies = decompressor.decode(&data).unwrap(); + let mut decompressor = weezl::decode::Decoder::new(weezl::BitOrder::Msb, lzw_code_size); + let indicies = match decompressor.decode(&data) { + Err(LzwError::InvalidCode) => Err(DecodeError::LzwInvalidCode), + Ok(o) => Ok(o), + }?; Ok(IndexedImage { image_descriptor, diff --git a/gifed/src/reader/mod.rs b/gifed/src/reader/mod.rs index b1bcc32..aed2142 100644 --- a/gifed/src/reader/mod.rs +++ b/gifed/src/reader/mod.rs @@ -295,6 +295,7 @@ pub enum DecodeError { IoError(std::io::Error), UnknownVersionString, UnexpectedEof, + LzwInvalidCode, ColorIndexOutOfBounds, InvalidVersion, UnknownBlock { byte: u8 }, @@ -312,6 +313,9 @@ impl fmt::Display for DecodeError { DecodeError::UnexpectedEof => { write!(f, "Found the end of the data at a weird spot") } + DecodeError::LzwInvalidCode => { + write!(f, "the LZW stream contained invalid data") + } DecodeError::ColorIndexOutOfBounds => { write!( f, |