Merge pull request #10274 from Snuffleupagus/out-of-order-trees

Fallback to an exhaustive search, in corrupt PDF files, for NameTrees/NumberTrees that are not correctly ordered (issue 10272)
This commit is contained in:
Tim van der Meij 2018-11-21 22:57:44 +01:00 committed by GitHub
commit 7b4f3035d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1648,7 +1648,7 @@ class NameOrNumberTree {
// contains the key we are looking for. // contains the key we are looking for.
while (kidsOrEntries.has('Kids')) { while (kidsOrEntries.has('Kids')) {
if (++loopCount > MAX_LEVELS) { if (++loopCount > MAX_LEVELS) {
warn('Search depth limit reached for "' + this._type + '" tree.'); warn(`Search depth limit reached for "${this._type}" tree.`);
return null; return null;
} }
@ -1696,6 +1696,19 @@ class NameOrNumberTree {
return xref.fetchIfRef(entries[m + 1]); 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; return null;
} }