Skip to content

Commit

Permalink
Merge pull request #8824 from Snuffleupagus/bug-1393476
Browse files Browse the repository at this point in the history
Prevent an infinite loop in `XRef.readXRef` by keeping track of already parsed tables (bug 1393476)
  • Loading branch information
Snuffleupagus committed Aug 24, 2017
2 parents f1819f4 + 4660cf8 commit 88167b5
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 88167b5

Please sign in to comment.