Fix a couple of integer overflows
This commit is contained in:
parent
a6711af84f
commit
0e3aeb782d
|
@ -92,7 +92,13 @@ impl<'a> GlyfTable<'a> {
|
||||||
|
|
||||||
fn for_each_point_in_simple_glyph<F>(&self, mut reader: &[u8], mut callback: F)
|
fn for_each_point_in_simple_glyph<F>(&self, mut reader: &[u8], mut callback: F)
|
||||||
-> Result<(), Error> where F: FnMut(&Point) {
|
-> 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));
|
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));
|
try!(reader.jump(mem::size_of::<i16>() * 4).map_err(Error::eof));
|
||||||
|
|
||||||
// Find out how many points we have.
|
// Find out how many points we have.
|
||||||
|
|
|
@ -297,12 +297,13 @@ impl<'a> Font<'a> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn shelf_height(&self, point_size: f32) -> u32 {
|
pub fn shelf_height(&self, point_size: f32) -> u32 {
|
||||||
|
// Add 2 to account for the border.
|
||||||
self.head
|
self.head
|
||||||
.max_glyph_bounds
|
.max_glyph_bounds
|
||||||
.pixel_rect_f(self.head.units_per_em, point_size)
|
.pixel_rect_f(self.head.units_per_em, point_size)
|
||||||
.to_i()
|
.to_i()
|
||||||
.size()
|
.size()
|
||||||
.height as u32
|
.height as u32 + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -38,6 +38,11 @@ impl RectPacker {
|
||||||
// Add a one-pixel border to prevent bleed.
|
// Add a one-pixel border to prevent bleed.
|
||||||
let alloc_size = *size + Size2D::new(2, 2);
|
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 =
|
let chosen_index_and_rect =
|
||||||
self.free_rects
|
self.free_rects
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in New Issue