From 00563e092abdf930897191cada196551d3b89ebf Mon Sep 17 00:00:00 2001 From: soupslurpr <92235850+soupslurpr@users.noreply.github.com> Date: Tue, 13 Feb 2024 09:33:27 -0800 Subject: [PATCH] Return error instead of using asssertion for Avif decoder unsupported or invalid bit depth (#2146) --- src/codecs/avif/decoder.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/codecs/avif/decoder.rs b/src/codecs/avif/decoder.rs index f8ff0c4410..1efe1443b5 100644 --- a/src/codecs/avif/decoder.rs +++ b/src/codecs/avif/decoder.rs @@ -9,7 +9,7 @@ use std::io::{self, Cursor, Read}; use std::marker::PhantomData; use std::mem; -use crate::error::{DecodingError, UnsupportedError, UnsupportedErrorKind}; +use crate::error::{DecodingError, ImageFormatHint, UnsupportedError, UnsupportedErrorKind}; use crate::{ColorType, ImageDecoder, ImageError, ImageFormat, ImageResult}; use dav1d::{PixelLayout, PlanarImageComponent}; @@ -56,7 +56,29 @@ impl AvifDecoder { .map(|x| x.ok().unwrap_or_default()) .map(|x| x.to_vec()); - assert_eq!(picture.bit_depth(), 8); + match picture.bit_depth() { + 8 => (), + 10 | 12 => { + return ImageResult::Err(ImageError::Unsupported( + UnsupportedError::from_format_and_kind( + ImageFormatHint::Exact(ImageFormat::Avif), + UnsupportedErrorKind::GenericFeature(format!( + "Only 8 bit depth is supported but was {}", + picture.bit_depth() + )), + ), + )) + } + _ => { + return ImageResult::Err(ImageError::Decoding(DecodingError::new( + ImageFormatHint::Exact(ImageFormat::Avif), + format!( + "Avif format does not support {} bit depth", + picture.bit_depth() + ), + ))) + } + }; Ok(AvifDecoder { inner: PhantomData, picture,