diff --git a/src/core/fonts.js b/src/core/fonts.js index f249e229b..9a29702db 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -5316,13 +5316,33 @@ var CFFStandardStrings = [ // Type1Font is also a CIDFontType0. var Type1Font = function Type1Font(name, file, properties) { + // Some bad generators embed pfb file as is, we have to strip 6-byte headers. + // Also, length1 and length2 might be off by 6 bytes as well. + // http://www.math.ubc.ca/~cass/piscript/type1.pdf + var PFB_HEADER_SIZE = 6; + var headerBlockLength = properties.length1; + var eexecBlockLength = properties.length2; + var pfbHeader = file.peekBytes(PFB_HEADER_SIZE); + var pfbHeaderPresent = pfbHeader[0] == 0x80 && pfbHeader[1] == 0x01; + if (pfbHeaderPresent) { + file.skip(PFB_HEADER_SIZE); + headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) | + (pfbHeader[3] << 8) | pfbHeader[2]; + } + // Get the data block containing glyphs and subrs informations - var headerBlock = new Stream(file.getBytes(properties.length1)); + var headerBlock = new Stream(file.getBytes(headerBlockLength)); var headerBlockParser = new Type1Parser(headerBlock); headerBlockParser.extractFontHeader(properties); + if (pfbHeaderPresent) { + pfbHeader = file.getBytes(PFB_HEADER_SIZE); + eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) | + (pfbHeader[3] << 8) | pfbHeader[2]; + } + // Decrypt the data blocks and retrieve it's content - var eexecBlock = new Stream(file.getBytes(properties.length2)); + var eexecBlock = new Stream(file.getBytes(eexecBlockLength)); var eexecBlockParser = new Type1Parser(eexecBlock, true); var data = eexecBlockParser.extractFontProgram(); for (var info in data.properties) diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index c330cd14a..3782cd90e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -23,6 +23,7 @@ !issue840.pdf !issue2074.pdf !scan-bad.pdf +!bug860632.pdf !pdfjsbad1586.pdf !freeculture.pdf !pdfkit_compressed.pdf diff --git a/test/pdfs/bug860632.pdf b/test/pdfs/bug860632.pdf new file mode 100644 index 000000000..587083aac Binary files /dev/null and b/test/pdfs/bug860632.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 4e9d7505f..6ccde5367 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -741,6 +741,13 @@ "link": true, "type": "load" }, + { "id": "bug860632", + "file": "pdfs/bug860632.pdf", + "md5": "b3cabf9249c8fee76f61f6b3b7fdd5fd", + "rounds": 1, + "lastPage": 1, + "type": "eq" + }, { "id": "issue1466", "file": "pdfs/issue1466.pdf", "md5": "8a8877432e5bb10cfd50d60488d947bb",