Skip to content

Commit

Permalink
(glyf) Fix endless loop during malformed file parsing.
Browse files Browse the repository at this point in the history
Closes #79
  • Loading branch information
RazrFalcon committed Nov 19, 2021
1 parent ba4fc75 commit 8d138e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- (glyf) Endless loop during malformed file parsing.

## [0.13.2] - 2021-10-28
### Added
Expand Down
11 changes: 5 additions & 6 deletions src/tables/glyf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ fn outline_impl(
data: &[u8],
depth: u8,
builder: &mut Builder,
) -> Option<Rect> {
) -> Option<Option<Rect>> {
if depth >= MAX_COMPONENTS {
return None;
}
Expand All @@ -525,8 +525,7 @@ fn outline_impl(
if let Some(glyph_data) = glyf_table.get(range) {
let transform = Transform::combine(builder.transform, comp.transform);
let mut b = Builder::new(transform, builder.bbox, builder.builder);
// We don't care about errors here.
let _ = outline_impl(loca_table, glyf_table, glyph_data, depth + 1, &mut b);
outline_impl(loca_table, glyf_table, glyph_data, depth + 1, &mut b)?;

// Take updated bbox.
builder.bbox = b.bbox;
Expand All @@ -536,10 +535,10 @@ fn outline_impl(
}

if builder.bbox.is_default() {
return None;
return Some(None);
}

builder.bbox.to_rect()
Some(builder.bbox.to_rect())
}

#[inline]
Expand Down Expand Up @@ -658,7 +657,7 @@ impl<'a> Table<'a> {
) -> Option<Rect> {
let mut b = Builder::new(Transform::default(), BBox::new(), builder);
let glyph_data = self.get(glyph_id)?;
outline_impl(self.loca_table, self.data, glyph_data, 0, &mut b)
outline_impl(self.loca_table, self.data, glyph_data, 0, &mut b)?
}

#[inline]
Expand Down

0 comments on commit 8d138e9

Please sign in to comment.