Skip to content

Commit 0189880

Browse files
author
Your Name
committed
Fix decoder panic with malformed (empty) sample format tag
I've included a minimal reproducer in tests/fuzz_images/oor_panic/sample-format-empty-vec.bin
1 parent 4adba46 commit 0189880

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ pub type Predictor = crate::tags::Predictor;
3838
pub type DeflateLevel = compression::DeflateLevel;
3939

4040
#[derive(Clone, Copy, PartialEq)]
41+
#[derive(Default)]
4142
pub enum Compression {
43+
#[default]
4244
Uncompressed,
4345
#[cfg(feature = "lzw")]
4446
Lzw,
@@ -47,11 +49,6 @@ pub enum Compression {
4749
Packbits,
4850
}
4951

50-
impl Default for Compression {
51-
fn default() -> Self {
52-
Self::Uncompressed
53-
}
54-
}
5552

5653
impl Compression {
5754
fn tag(&self) -> CompressionMethod {
85 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)