Merge pull request #305 from Mrmaxmeier/fix-malformed-sample-format
Fix decoder panic with malformed (empty) sample format tag
This commit is contained in:
3 files changed
+8
-10
No files matched your search
@@ -145,12 +145,15 @@ impl Image {
|
|||||||
.map(SampleFormat::from_u16_exhaustive)
|
.map(SampleFormat::from_u16_exhaustive)
|
||||||
.collect();
|
.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.
|
// 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());
|
return Err(TiffUnsupportedError::UnsupportedSampleFormat(sample_format).into());
|
||||||
}
|
}
|
||||||
|
format
|
||||||
sample_format[0]
|
|
||||||
}
|
}
|
||||||
None => SampleFormat::Uint,
|
None => SampleFormat::Uint,
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-7
@@ -37,8 +37,9 @@ pub type Predictor = crate::tags::Predictor;
|
|||||||
#[cfg(feature = "deflate")]
|
#[cfg(feature = "deflate")]
|
||||||
pub type DeflateLevel = compression::DeflateLevel;
|
pub type DeflateLevel = compression::DeflateLevel;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, PartialEq, Default)]
|
||||||
pub enum Compression {
|
pub enum Compression {
|
||||||
|
#[default]
|
||||||
Uncompressed,
|
Uncompressed,
|
||||||
#[cfg(feature = "lzw")]
|
#[cfg(feature = "lzw")]
|
||||||
Lzw,
|
Lzw,
|
||||||
@@ -47,12 +48,6 @@ pub enum Compression {
|
|||||||
Packbits,
|
Packbits,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Compression {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Uncompressed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Compression {
|
impl Compression {
|
||||||
fn tag(&self) -> CompressionMethod {
|
fn tag(&self) -> CompressionMethod {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user