Skip to content

Commit

Permalink
Prevent an infinite loop in XRef.readXRef by keeping track of alrea…
Browse files Browse the repository at this point in the history
…dy parsed tables (bug 1393476)

With this patch, not only is the infinite loop prevented, but we're also able to actually render the file (which e.g. Adobe Reader isn't able to).

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1393476.
  • Loading branch information
Snuffleupagus committed Aug 24, 2017
1 parent e9ba549 commit 4660cf8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,22 @@ var XRef = (function XRefClosure() {

readXRef: function XRef_readXRef(recoveryMode) {
var stream = this.stream;
// Keep track of already parsed XRef tables, to prevent an infinite loop
// when parsing corrupt PDF files where e.g. the /Prev entries create a
// circular dependency between tables (fixes bug1393476.pdf).
let startXRefParsedCache = Object.create(null);

try {
while (this.startXRefQueue.length) {
var startXRef = this.startXRefQueue[0];

if (startXRefParsedCache[startXRef]) {
warn('readXRef - skipping XRef table since it was already parsed.');
this.startXRefQueue.shift();
continue;
}
startXRefParsedCache[startXRef] = true;

stream.pos = startXRef + stream.start;

var parser = new Parser(new Lexer(stream), true, this);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/bug1393476.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=8900754
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,13 @@
"link": false,
"type": "eq"
},
{ "id": "bug1393476",
"file": "pdfs/bug1393476.pdf",
"md5": "163ee8727c77f27ee651eec777bb20a9",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "bug1252420",
"file": "pdfs/bug1252420.pdf",
"md5": "f21c911b9b655972b06ef782a1fa6a17",
Expand Down

0 comments on commit 4660cf8

Please sign in to comment.