Prevent panics in parse_ihdr_header (#392)
This commit is contained in:
parent
f44b5aa2d0
commit
f2e89140ed
1 changed files with 3 additions and 1 deletions
|
|
@ -140,6 +140,8 @@ pub fn parse_next_header<'a>(
|
|||
}
|
||||
|
||||
pub fn parse_ihdr_header(byte_data: &[u8]) -> PngResult<IhdrData> {
|
||||
// This eliminates bounds checks for the rest of the function
|
||||
let interlaced = byte_data.get(12).copied().ok_or(PngError::TruncatedData)?;
|
||||
let mut rdr = Cursor::new(&byte_data[0..8]);
|
||||
Ok(IhdrData {
|
||||
color_type: match byte_data[9] {
|
||||
|
|
@ -162,6 +164,6 @@ pub fn parse_ihdr_header(byte_data: &[u8]) -> PngResult<IhdrData> {
|
|||
height: rdr.read_u32::<BigEndian>().unwrap(),
|
||||
compression: byte_data[10],
|
||||
filter: byte_data[11],
|
||||
interlaced: byte_data[12],
|
||||
interlaced,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue