Workaround for some bad Type1 data

This commit is contained in:
Yury Delendik 2013-10-31 09:10:08 -05:00
parent f7b2b2e1f2
commit cd44093891
4 changed files with 30 additions and 2 deletions

View File

@ -5291,13 +5291,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)

View File

@ -23,6 +23,7 @@
!issue840.pdf
!issue2074.pdf
!scan-bad.pdf
!bug860632.pdf
!pdfjsbad1586.pdf
!freeculture.pdf
!pdfkit_compressed.pdf

BIN
test/pdfs/bug860632.pdf Normal file

Binary file not shown.

View File

@ -725,6 +725,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",