1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #11577 from Snuffleupagus/Pages-tree-refs

Prevent circular references in the /Pages tree
This commit is contained in:
Tim van der Meij 2020-02-27 23:36:11 +01:00 committed by GitHub
commit e1586016c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 155 additions and 8 deletions

View file

@ -731,6 +731,7 @@ class Catalog {
getPageDict(pageIndex) {
const capability = createPromiseCapability();
const nodesToVisit = [this.catDict.getRaw("Pages")];
const visitedNodes = new RefSet();
const xref = this.xref,
pageKidsCountCache = this.pageKidsCountCache;
let count,
@ -747,6 +748,14 @@ class Catalog {
currentPageIndex += count;
continue;
}
// Prevent circular references in the /Pages tree.
if (visitedNodes.has(currentNode)) {
capability.reject(
new FormatError("Pages tree contains circular reference.")
);
return;
}
visitedNodes.put(currentNode);
xref.fetchAsync(currentNode).then(function(obj) {
if (isDict(obj, "Page") || (isDict(obj) && !obj.has("Kids"))) {