From 192907e0d29ed72dd8f5322692ad39afb64fb909 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 1 Oct 2015 14:46:03 +0200 Subject: [PATCH] Make `XRef_indexObjects` even more robust against bad PDF files, by checking for the existence of 'trailer' if 'xref' is not found Fixes http://www.cyjack.com/cognition/Terence%20McKenna%20-%20Lectures%20on%20Alchemy.pdf. --- src/core/obj.js | 4 ++ test/pdfs/.gitignore | 1 + test/pdfs/xref_command_missing.pdf | 66 ++++++++++++++++++++++++++++++ test/test_manifest.json | 7 ++++ 4 files changed, 78 insertions(+) create mode 100644 test/pdfs/xref_command_missing.pdf diff --git a/src/core/obj.js b/src/core/obj.js index be62eab55..204fd3fb5 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -1118,6 +1118,10 @@ var XRef = (function XRefClosure() { } position += contentLength; + } else if (token.indexOf('trailer') === 0 && + (token.length === 7 || /\s/.test(token[7]))) { + trailers.push(position); + position += skipUntil(buffer, position, startxrefBytes); } else { position += token.length + 1; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index de2d8b754..29199dfe4 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -4,6 +4,7 @@ !tracemonkey.pdf !franz.pdf !franz_2.pdf +!xref_command_missing.pdf !issue2391-1.pdf !issue2391-2.pdf !issue5801.pdf diff --git a/test/pdfs/xref_command_missing.pdf b/test/pdfs/xref_command_missing.pdf new file mode 100644 index 000000000..2795a146c --- /dev/null +++ b/test/pdfs/xref_command_missing.pdf @@ -0,0 +1,66 @@ +%PDF-1.7 +%âãÏÓ +1 0 obj +<< +/Pages 2 0 R +/Type /Catalog +>> +endobj +2 0 obj +<< +/Kids [3 0 R] +/Type /Pages +/Count 1 +>> +endobj +3 0 obj +<< +/Parent 2 0 R +/Resources +<< +/Font +<< +/F1 4 0 R +>> +>> +/MediaBox [0 0 200 50] +/Type /Page +/Contents 5 0 R +>> +endobj +4 0 obj +<< +/BaseFont /Times-Roman +/Subtype /Type1 +/Type /Font +/Encoding /WinAnsiEncoding +>> +endobj +5 0 obj +<< +/Length 48 +>> +stream +BT +10 20 TD +/F1 20 Tf +(Reduced test-case) Tj +ET + +endstream +endobj +0000000000 65535 f +0000000015 00000 n +0000000066 00000 n +0000000125 00000 n +0000000254 00000 n +0000000355 00000 n +trailer + +<< +/Root 1 0 R +/Size 6 +>> +startxref +455 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index 834e43145..12ebb9b31 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -572,6 +572,13 @@ "link": false, "type": "eq" }, + { "id": "xref_command_missing", + "file": "pdfs/xref_command_missing.pdf", + "md5": "06cdb0f13cfeff41d6bfb24b7bbe1268", + "rounds": 1, + "link": false, + "type": "load" + }, { "id": "issue5501", "file": "pdfs/issue5501.pdf", "md5": "55a60699728fc92f491a2d7d490474e4",