Skip to content

Commit

Permalink
Return error instead of using asssertion for Avif decoder unsupported…
Browse files Browse the repository at this point in the history
… or invalid bit depth (#2146)
  • Loading branch information
soupslurpr authored Feb 13, 2024
1 parent 5d73d50 commit 00563e0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/codecs/avif/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -56,7 +56,29 @@ impl<R: Read> AvifDecoder<R> {
.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,
Expand Down

0 comments on commit 00563e0

Please sign in to comment.