diff --git a/src/decoder/image.rs b/src/decoder/image.rs index c037e31..6f54aae 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -466,6 +466,7 @@ impl Image { output_width: usize, byte_order: ByteOrder, chunk_index: u32, + limits: &Limits, ) -> TiffResult<()> { // Validate that the provided buffer is of the expected type. let color_type = self.colortype()?; @@ -520,6 +521,9 @@ impl Image { .ok_or(TiffError::FormatError( TiffFormatError::InconsistentSizesEncountered, ))?; + if *compressed_bytes > limits.intermediate_buffer_size as u64 { + return Err(TiffError::LimitsExceeded); + } let byte_len = buffer.byte_len(); let compression_method = self.compression_method; diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 5fa1812..0612db9 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -1042,6 +1042,7 @@ impl Decoder { output_width, byte_order, chunk_index, + &self.limits, )?; Ok(()) @@ -1168,6 +1169,7 @@ impl Decoder { width as usize, byte_order, chunk as u32, + &self.limits, )?; }