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

Prevent circular references in the /Pages tree

This commit is contained in:
Jonas Jenwald 2020-02-08 17:43:53 +01:00
parent e2b30e9e9c
commit 3c7b7be100
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"))) {