Merge pull request #305 from Mrmaxmeier/fix-malformed-sample-format

Fix decoder panic with malformed (empty) sample format tag
This commit is contained in:
Aurelia Molzer authored and GitHub committed 2025-10-27 15:01:59 +00:00
commit 2ccbe132e0
3 files changed
+8 -10

No files matched your search

+6 -3
View File
@@ -145,12 +145,15 @@ impl Image {
.map(SampleFormat::from_u16_exhaustive)
.collect();
let Some(format) = sample_format.first().copied() else {
// Reject empty sample formats
return Err(TiffFormatError::InvalidTagValueType(Tag::SampleFormat).into());
};
// TODO: for now, only homogenous formats across samples are supported.
if !sample_format.windows(2).all(|s| s[0] == s[1]) {
if !sample_format.iter().all(|&s| s == format) {
return Err(TiffUnsupportedError::UnsupportedSampleFormat(sample_format).into());
}
sample_format[0]
format
}
None => SampleFormat::Uint,
};
+2 -7
View File
@@ -37,8 +37,9 @@ pub type Predictor = crate::tags::Predictor;
#[cfg(feature = "deflate")]
pub type DeflateLevel = compression::DeflateLevel;
#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Default)]
pub enum Compression {
#[default]
Uncompressed,
#[cfg(feature = "lzw")]
Lzw,
@@ -47,12 +48,6 @@ pub enum Compression {
Packbits,
}
impl Default for Compression {
fn default() -> Self {
Self::Uncompressed
}
}
impl Compression {
fn tag(&self) -> CompressionMethod {
match self {