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 000000000..f8825753a Binary files /dev/null and b/test/pdfs/bug1250079.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 8816c1706..12182fd96 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -730,6 +730,13 @@ "link": false, "type": "eq" }, + { "id": "bug1250079", + "file": "pdfs/bug1250079.pdf", + "md5": "a1dd21a70ae7097d96273e85a80b26ef", + "rounds": 1, + "link": false, + "type": "load" + }, { "id": "hudsonsurvey", "file": "pdfs/hudsonsurvey.pdf", "md5": "bf0e6576a7b6c2fe7485bce1b78e006f",