Skip to content

Commit c09d79b

Browse files
committed
Ensure memory usage is checked arithmetic
1 parent 7e51cc9 commit c09d79b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/decoder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,12 @@ impl<R: Read> Decoder<R> {
464464

465465
let frame = self.frame.as_ref().unwrap();
466466

467-
if frame.output_size.width as u64 * frame.output_size.height as u64 * frame.components.len() as u64 > self.decoding_buffer_size_limit as u64 {
467+
if {
468+
let required_mem = frame.components.len()
469+
.checked_mul(frame.output_size.width.into())
470+
.and_then(|m| m.checked_mul(frame.output_size.height.into()));
471+
required_mem.map_or(true, |m| self.decoding_buffer_size_limit < m)
472+
} {
468473
return Err(Error::Format("size of decoded image exceeds maximum allowed size".to_owned()));
469474
}
470475

0 commit comments

Comments
 (0)