Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent an infinite loop in XRef.readXRef by keeping track of already parsed tables (bug 1393476) #8824

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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