Handle possible JPEG decoder errors

The JPEG decoder may fail and panic the TIFF decoder. This commit
converts the JPEG `Format(String)` error to a TIFF `Format(String)`
error.

Fixes #168
This commit is contained in:
Micah Snyder committed 2022-09-02 15:02:23 -07:00
1 parent 2ec1ab7489
commit d32adf8ef4
1 file changed
+8 -1
+8 -1
View File
@@ -345,7 +345,14 @@ impl Image {
let jpeg_reader = JpegReader::new(reader, compressed_length, jpeg_tables)?;
let mut decoder = jpeg::Decoder::new(jpeg_reader);
let data = decoder.decode().unwrap();
let data = match decoder.decode() {
Ok(data) => data,
Err(e) => {
return Err(TiffError::FormatError(TiffFormatError::Format(
e.to_string(),
)))
}
};
Box::new(Cursor::new(data))
}