Fix a couple of integer overflows

This commit is contained in:
Patrick Walton 2017-02-07 16:53:37 -08:00
parent a6711af84f
commit 0e3aeb782d
3 changed files with 13 additions and 1 deletions

View File

@ -92,7 +92,13 @@ impl<'a> GlyfTable<'a> {
fn for_each_point_in_simple_glyph<F>(&self, mut reader: &[u8], mut callback: F)
-> Result<(), Error> where F: FnMut(&Point) {
// Determine how many contours we have.
let number_of_contours = try!(reader.read_i16::<BigEndian>().map_err(Error::eof));
if number_of_contours == 0 {
return Ok(())
}
// Skip over the rest of the header.
try!(reader.jump(mem::size_of::<i16>() * 4).map_err(Error::eof));
// Find out how many points we have.

View File

@ -297,12 +297,13 @@ impl<'a> Font<'a> {
#[inline]
pub fn shelf_height(&self, point_size: f32) -> u32 {
// Add 2 to account for the border.
self.head
.max_glyph_bounds
.pixel_rect_f(self.head.units_per_em, point_size)
.to_i()
.size()
.height as u32
.height as u32 + 2
}
#[inline]

View File

@ -38,6 +38,11 @@ impl RectPacker {
// Add a one-pixel border to prevent bleed.
let alloc_size = *size + Size2D::new(2, 2);
// If the allocation size is less than our shelf height, we will always fail.
if alloc_size.height > self.shelf_height {
return Err(())
}
let chosen_index_and_rect =
self.free_rects
.iter()