From de5e7b487c2fbb0e27e676826673206600d23a5f Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Sun, 26 Feb 2023 14:38:10 +0800 Subject: [PATCH] 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. --- Userland/Libraries/LibPDF/Fonts/Type1FontProgram.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibPDF/Fonts/Type1FontProgram.cpp b/Userland/Libraries/LibPDF/Fonts/Type1FontProgram.cpp index 584a16c3eb..94a8a53a9a 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1FontProgram.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1FontProgram.cpp @@ -271,7 +271,7 @@ PDFErrorOr 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::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::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; }