LibPDF: Improve Type2 hint counting
There were two issues with how we counted hints with Type2 CharString commands: the first was that we assumed a single hint per command, even though there are commands that accept multiple hints thanks to taking a variable number of operands; and secondly, the hintmask/ctrlmask commands can also take operands (i.e., hints) themselves in certain situations. This commit fixes these two issues by correctly counting hints in both cases. This in turn fixes cases when there were more than 8 hints in total, therefore a hintmask/ctrlmask command needed to read more than one byte past the operator itself.
This commit is contained in:
parent
bf61f94413
commit
de5e7b487c
Notes:
sideshowbarker
2024-07-16 23:34:44 +09:00
Author: https://github.com/rtobar Commit: https://github.com/SerenityOS/serenity/commit/de5e7b487c Pull-request: https://github.com/SerenityOS/serenity/pull/17683
1 changed files with 4 additions and 2 deletions
|
@ -271,7 +271,7 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
|||
|
||||
// hints operators
|
||||
case HStemHM:
|
||||
state.n_hints++;
|
||||
state.n_hints += state.sp / 2;
|
||||
[[fallthrough]];
|
||||
case HStem:
|
||||
maybe_read_width(Odd);
|
||||
|
@ -279,7 +279,7 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
|||
break;
|
||||
|
||||
case VStemHM:
|
||||
state.n_hints++;
|
||||
state.n_hints += state.sp / 2;
|
||||
[[fallthrough]];
|
||||
case VStem:
|
||||
maybe_read_width(Odd);
|
||||
|
@ -289,9 +289,11 @@ PDFErrorOr<Type1FontProgram::Glyph> Type1FontProgram::parse_glyph(ReadonlyBytes
|
|||
case Hintmask:
|
||||
case Cntrmask: {
|
||||
maybe_read_width(Odd);
|
||||
state.n_hints += state.sp / 2;
|
||||
auto hint_bytes = (state.n_hints + 8 - 1) / 8;
|
||||
TRY(require(hint_bytes));
|
||||
i += hint_bytes;
|
||||
state.sp = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue