about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-07-15 18:59:36 -0500
committergennyble <gen@nyble.dev>2023-07-15 18:59:36 -0500
commit33280b7c9e8f982d8f22ee793489025448ee2694 (patch)
tree56b08c18d9648dfb57a190f59d4e647717640647
parent2ab2e7635fbc5ff9b3dae625569053995e117deb (diff)
downloadgifed-33280b7c9e8f982d8f22ee793489025448ee2694.tar.gz
gifed-33280b7c9e8f982d8f22ee793489025448ee2694.zip
weezl errors propagate instead of panic
is that how you spell that workd?
-rw-r--r--gifed/src/block/indexedimage.rs9
-rw-r--r--gifed/src/reader/mod.rs4
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,