Skip to content

Commit

Permalink
(CFF) Fixed panic and stack overflow during seac resolving.
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
RazrFalcon committed Nov 22, 2021
1 parent f440523 commit f28f7a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- (CFF) Panic during `seac` resolving.
- (CFF) Stack overflow during `seac` resolving.

## [0.13.3] - 2021-11-19
### Fixed
Expand Down
6 changes: 5 additions & 1 deletion src/tables/cff/cff1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,17 @@ fn _parse_char_string(
let dy = p.stack.pop();
let dx = p.stack.pop();

if !ctx.width_parsed {
if !ctx.width_parsed && !p.stack.is_empty() {
p.stack.pop();
ctx.width_parsed = true;
}

ctx.has_seac = true;

if depth == STACK_LIMIT {
return Err(CFFError::NestingLimitReached);
}

let base_char_string = ctx.metadata.char_strings.get(u32::from(base_char.0))
.ok_or(CFFError::InvalidSeacCode)?;
_parse_char_string(ctx, base_char_string, depth + 1, p)?;
Expand Down
8 changes: 8 additions & 0 deletions tests/tables/cff1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,14 @@ test_cs_err!(multiple_endchar, &[
UInt8(operator::ENDCHAR),
], CFFError::DataAfterEndChar);

test_cs_err!(seac_with_not_enough_data, &[
CFFInt(0),
CFFInt(0),
CFFInt(0),
CFFInt(0),
UInt8(operator::ENDCHAR),
], CFFError::NestingLimitReached);

test_cs_err!(operands_overflow, &[
CFFInt(0), CFFInt(1), CFFInt(2), CFFInt(3), CFFInt(4), CFFInt(5), CFFInt(6), CFFInt(7), CFFInt(8), CFFInt(9),
CFFInt(0), CFFInt(1), CFFInt(2), CFFInt(3), CFFInt(4), CFFInt(5), CFFInt(6), CFFInt(7), CFFInt(8), CFFInt(9),
Expand Down

0 comments on commit f28f7a5

Please sign in to comment.