From 544d29f5cbf085012d4365d9751cc88a1f2e9aba Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 24 Feb 2016 17:56:28 +0100 Subject: [PATCH] Add a `recoveryMode` that suppresses errors from the `Parser`, and utilize it when searching for the main trailer in `XRef_indexObjects` (bug 1250079) Instead of having `Parser_getObj` fail unconditionally for the referenced PDF file, this patch attempts to let searching for the main trailer continue even if there are errors. Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1250079. --- src/core/obj.js | 6 ++++-- src/core/parser.js | 13 ++++++++++--- test/pdfs/.gitignore | 1 + test/pdfs/bug1250079.pdf | Bin 0 -> 711 bytes test/test_manifest.json | 7 +++++++ 5 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 test/pdfs/bug1250079.pdf diff --git a/src/core/obj.js b/src/core/obj.js index b104f58fe..f6150a1fa 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -970,13 +970,15 @@ var XRef = (function XRefClosure() { var dict; for (i = 0, ii = trailers.length; i < ii; ++i) { stream.pos = trailers[i]; - var parser = new Parser(new Lexer(stream), true, this); + var parser = new Parser(new Lexer(stream), /* allowStreams = */ true, + /* xref = */ this, /* recoveryMode = */ true); var obj = parser.getObj(); if (!isCmd(obj, 'trailer')) { continue; } // read the trailer dictionary - if (!isDict(dict = parser.getObj())) { + dict = parser.getObj(); + if (!isDict(dict)) { continue; } // taking the first one with 'ID' diff --git a/src/core/parser.js b/src/core/parser.js index cd93beb35..eeb42a00b 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -66,10 +66,11 @@ function isEOF(v) { var MAX_LENGTH_TO_CACHE = 1000; var Parser = (function ParserClosure() { - function Parser(lexer, allowStreams, xref) { + function Parser(lexer, allowStreams, xref, recoveryMode) { this.lexer = lexer; this.allowStreams = allowStreams; this.xref = xref; + this.recoveryMode = recoveryMode || false; this.imageCache = Object.create(null); this.refill(); } @@ -115,7 +116,10 @@ var Parser = (function ParserClosure() { array.push(this.getObj(cipherTransform)); } if (isEOF(this.buf1)) { - error('End of file inside array'); + if (!this.recoveryMode) { + error('End of file inside array'); + } + return array; } this.shift(); return array; @@ -136,7 +140,10 @@ var Parser = (function ParserClosure() { dict.set(key, this.getObj(cipherTransform)); } if (isEOF(this.buf1)) { - error('End of file inside dictionary'); + if (!this.recoveryMode) { + error('End of file inside dictionary'); + } + return dict; } // Stream objects are not allowed inside content streams or diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 6cbda038d..610cfb65e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -99,6 +99,7 @@ !bug911034.pdf !bug1108301.pdf !bug1157493.pdf +!bug1250079.pdf !pdfjsbad1586.pdf !freeculture.pdf !issue6006.pdf diff --git a/test/pdfs/bug1250079.pdf b/test/pdfs/bug1250079.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f8825753ada0f4f1cc90c6055b13ba9cc9170471 GIT binary patch literal 711 zcmZWmzfTlF6t*<4q45uRk&tMCGqZcM2l0Y<9G4IzIhQpMFC@<0&8|!CW@L9S0b+rH zhK6WjVe~jR1+1hfP!*}n4M`C9WIE~Vo=`xR`>iaW-EP3lGOyaY6RQZxN~|8LG#&!O zF|EgFh;2}WJd!HPo@2?ej5JH6=s`6AW@p5p2BgmNTL^cm{Ro-EDJ@Um#b6!g1F%aU zh;X?7%|wPk(F0l>^f-4phFD