Skip to content

Commit

Permalink
Fix capacity overflow in JpegReader
Browse files Browse the repository at this point in the history
  • Loading branch information
anfedotoff committed Feb 5, 2023
1 parent 4dea7c4 commit 8fa175c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/decoder/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,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()?;
Expand Down Expand Up @@ -511,6 +512,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;
Expand Down
2 changes: 2 additions & 0 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ impl<R: Read + Seek> Decoder<R> {
output_width,
byte_order,
chunk_index,
&self.limits,
)?;

Ok(())
Expand Down Expand Up @@ -1168,6 +1169,7 @@ impl<R: Read + Seek> Decoder<R> {
width as usize,
byte_order,
chunk as u32,
&self.limits,
)?;
}

Expand Down

0 comments on commit 8fa175c

Please sign in to comment.