From 6a8c59130129b06eea4b53c359732118f46b05bf Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 25 Mar 2020 13:57:51 +0100 Subject: [PATCH] Improve detection of binary/ASCII `eexec` encrypted Type1 font programs in `Type1Parser` (issue 11740) The PDF document, in the referenced issue, actually contains ASCII-encoded Type1 data which we currently *incorrectly* identify as binary. According to the specification, see https://www-cdf.fnal.gov/offline/PostScript/T1_SPEC.PDF#[{%22num%22%3A203%2C%22gen%22%3A0}%2C{%22name%22%3A%22XYZ%22}%2C87%2C452%2Cnull], the current checks are insufficient to decide between binary/ASCII encoded Type1 font programs. --- src/core/type1_parser.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/type1_parser.js b/src/core/type1_parser.js index 76f5c3d2f..2b8bb659c 100644 --- a/src/core/type1_parser.js +++ b/src/core/type1_parser.js @@ -457,10 +457,14 @@ var Type1Parser = (function Type1ParserClosure() { if (encrypted) { var data = stream.getBytes(); var isBinary = !( - isHexDigit(data[0]) && + (isHexDigit(data[0]) || isWhiteSpace(data[0])) && isHexDigit(data[1]) && isHexDigit(data[2]) && - isHexDigit(data[3]) + isHexDigit(data[3]) && + isHexDigit(data[4]) && + isHexDigit(data[5]) && + isHexDigit(data[6]) && + isHexDigit(data[7]) ); stream = new Stream( isBinary