Skip to content

Commit

Permalink
ostree: Check out of band for read frame offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlarsson committed Oct 22, 2019
1 parent 7fd8e5b commit f87125e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/ostree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,24 @@ impl<'a> SubVariant<'a> {
return Err(OstreeError::InternalError(format!("Framing error: can't read frame offset at {}", offset)));
}
let data = &self.data[offset..offset + framing_size];
return Ok(
match framing_size {
0 => 0,
1 => usize::from(data[0]),
2 => usize::from(LittleEndian::read_u16(data)),
4 => LittleEndian::read_u32(data) as usize,
8 => {
let len64 = LittleEndian::read_u64(data);
if len64 > ::std::usize::MAX as u64 {
return Err(OstreeError::InternalError("Framing error: To large framing size fror usize".to_string()));
}
len64 as usize
},
_ => return Err(OstreeError::InternalError(format!("Framing error: Unexpected framing size {}", framing_size))),
})
let offset = match framing_size {
0 => 0,
1 => usize::from(data[0]),
2 => usize::from(LittleEndian::read_u16(data)),
4 => LittleEndian::read_u32(data) as usize,
8 => {
let len64 = LittleEndian::read_u64(data);
if len64 > ::std::usize::MAX as u64 {
return Err(OstreeError::InternalError("Framing error: To large framing size fror usize".to_string()));
}
len64 as usize
},
_ => return Err(OstreeError::InternalError(format!("Framing error: Unexpected framing size {}", framing_size))),
};
if offset > self.data.len() {
return Err(OstreeError::InternalError(format!("Framing error: out of bounds offset at {}", offset)));
};
return Ok(offset)
}

fn pad(&self, cur: usize, alignment: usize) -> usize {
Expand Down

0 comments on commit f87125e

Please sign in to comment.