Skip to content

Commit

Permalink
When decoding interlaced files use info from current chunk instead of…
Browse files Browse the repository at this point in the history
… the previous one. Fixes panic on malformed files (image-rs#79) and also likely fixes decoding of some exotic PNGs out there. Found via afl.rs
  • Loading branch information
Shnatsel committed Jun 27, 2018
1 parent a5faaf2 commit e221ae9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ impl<R: Read> Reader<R> {
pub fn next_interlaced_row(&mut self) -> Result<Option<(&[u8], Option<(u8, u32, u32)>)>, DecodingError> {
use common::ColorType::*;
let transform = self.transform;
let (color_type, bit_depth, trns) = {
let info = get_info!(self);
(info.color_type, info.bit_depth as u8, info.trns.is_some())
};
if transform == ::Transformations::IDENTITY {
self.next_raw_interlaced_row()
} else {
Expand All @@ -261,6 +257,10 @@ impl<R: Read> Reader<R> {
// swap back
let _ = mem::replace(&mut self.processed, buffer);
if got_next {
let (color_type, bit_depth, trns) = {
let info = get_info!(self);
(info.color_type, info.bit_depth as u8, info.trns.is_some())
};
let output_buffer = if let Some((_, _, width)) = adam7 {
let width = self.line_size(width);
&mut self.processed[..width]
Expand Down

0 comments on commit e221ae9

Please sign in to comment.