diff --git a/src/core/obj.js b/src/core/obj.js index f05d373a2..019fe5bf6 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -1648,7 +1648,7 @@ class NameOrNumberTree { // contains the key we are looking for. while (kidsOrEntries.has('Kids')) { if (++loopCount > MAX_LEVELS) { - warn('Search depth limit reached for "' + this._type + '" tree.'); + warn(`Search depth limit reached for "${this._type}" tree.`); return null; } @@ -1696,6 +1696,19 @@ class NameOrNumberTree { return xref.fetchIfRef(entries[m + 1]); } } + + // Fallback to an exhaustive search, in an attempt to handle corrupt + // PDF files where keys are not correctly ordered (fixes issue 10272). + info(`Falling back to an exhaustive search, for key "${key}", ` + + `in "${this._type}" tree.`); + for (let m = 0, mm = entries.length; m < mm; m += 2) { + const currentKey = xref.fetchIfRef(entries[m]); + if (currentKey === key) { + warn(`The "${key}" key was found at an incorrect, ` + + `i.e. out-of-order, position in "${this._type}" tree.`); + return xref.fetchIfRef(entries[m + 1]); + } + } } return null; }