From d90ad429f6eb345b173ec042dcfe2d6c150701ff Mon Sep 17 00:00:00 2001 From: Jonas Date: Thu, 8 Aug 2013 19:02:11 +0200 Subject: [PATCH] Enable loading of PDFs with invalid document information dictionaries --- src/core.js | 12 ++++++++---- test/pdfs/issue2853.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/pdfs/issue2853.pdf.link diff --git a/src/core.js b/src/core.js index 3e1ea9339..b0d9fda81 100644 --- a/src/core.js +++ b/src/core.js @@ -457,9 +457,13 @@ var PDFDocument = (function PDFDocumentClosure() { PDFFormatVersion: this.pdfFormatVersion, IsAcroFormPresent: !!this.acroForm }; - if (this.xref.trailer.has('Info')) { - var infoDict = this.xref.trailer.get('Info'); - + var infoDict; + try { + infoDict = this.xref.trailer.get('Info'); + } catch (err) { + info('The document information dictionary is invalid.'); + } + if (infoDict) { var validEntries = DocumentInfoValidators.entries; // Only fill the document info with valid entries from the spec. for (var key in validEntries) { @@ -468,7 +472,7 @@ var PDFDocument = (function PDFDocumentClosure() { // Make sure the value conforms to the spec. if (validEntries[key](value)) { docInfo[key] = typeof value !== 'string' ? value : - stringToPDFString(value); + stringToPDFString(value); } else { info('Bad value in document info for "' + key + '"'); } diff --git a/test/pdfs/issue2853.pdf.link b/test/pdfs/issue2853.pdf.link new file mode 100644 index 000000000..36db6694d --- /dev/null +++ b/test/pdfs/issue2853.pdf.link @@ -0,0 +1 @@ +http://www.celgene.de/Patienten/Newsletter-Epigenetik-201301.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 510cb35f4..52d432a34 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1310,5 +1310,14 @@ "firstPage": 1, "lastPage": 1, "type": "eq" + }, + { "id": "issue2853", + "file": "pdfs/issue2853.pdf", + "md5": "9f0ad95ef0b243ee8813c4eca0f7a042", + "rounds": 1, + "link": true, + "firstPage": 1, + "lastPage": 1, + "type": "load" } ]