Skip to content

Commit 2ccbe13

Browse files
authored
Merge pull request #305 from Mrmaxmeier/fix-malformed-sample-format
Fix decoder panic with malformed (empty) sample format tag
2 parents 4adba46 + 714e470 commit 2ccbe13

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/decoder/image.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@ impl Image {
145145
.map(SampleFormat::from_u16_exhaustive)
146146
.collect();
147147

148+
let Some(format) = sample_format.first().copied() else {
149+
// Reject empty sample formats
150+
return Err(TiffFormatError::InvalidTagValueType(Tag::SampleFormat).into());
151+
};
148152
// TODO: for now, only homogenous formats across samples are supported.
149-
if !sample_format.windows(2).all(|s| s[0] == s[1]) {
153+
if !sample_format.iter().all(|&s| s == format) {
150154
return Err(TiffUnsupportedError::UnsupportedSampleFormat(sample_format).into());
151155
}
152-
153-
sample_format[0]
156+
format
154157
}
155158
None => SampleFormat::Uint,
156159
};

src/encoder/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ pub type Predictor = crate::tags::Predictor;
3737
#[cfg(feature = "deflate")]
3838
pub type DeflateLevel = compression::DeflateLevel;
3939

40-
#[derive(Clone, Copy, PartialEq)]
40+
#[derive(Clone, Copy, PartialEq, Default)]
4141
pub enum Compression {
42+
#[default]
4243
Uncompressed,
4344
#[cfg(feature = "lzw")]
4445
Lzw,
@@ -47,12 +48,6 @@ pub enum Compression {
4748
Packbits,
4849
}
4950

50-
impl Default for Compression {
51-
fn default() -> Self {
52-
Self::Uncompressed
53-
}
54-
}
55-
5651
impl Compression {
5752
fn tag(&self) -> CompressionMethod {
5853
match self {
85 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)