From d1ad9b26648966ad8ffb87a5e182da9749a06c15 Mon Sep 17 00:00:00 2001 From: Alan Race Date: Tue, 7 Mar 2023 09:15:10 +0100 Subject: [PATCH] Don't panic when parsing metadata when custom compression is used --- src/decoder/image.rs | 3 +-- src/tags.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 6f54aae..89b0209 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -109,8 +109,7 @@ impl Image { // Try to parse both the compression method and the number, format, and bits of the included samples. // If they are not explicitly specified, those tags are reset to their default values and not carried from previous images. let compression_method = match tag_reader.find_tag(Tag::Compression)? { - Some(val) => CompressionMethod::from_u16(val.into_u16()?) - .ok_or(TiffUnsupportedError::UnknownCompressionMethod)?, + Some(val) => CompressionMethod::from_u16_exhaustive(val.into_u16()?), None => CompressionMethod::None, }; diff --git a/src/tags.rs b/src/tags.rs index cbf7472..3b86dc1 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -172,7 +172,7 @@ pub enum Type(u16) { tags! { /// See [TIFF compression tags](https://www.awaresystems.be/imaging/tiff/tifftags/compression.html) /// for reference. -pub enum CompressionMethod(u16) { +pub enum CompressionMethod(u16) unknown("A custom compression method") { None = 1, Huffman = 2, Fax3 = 3,