1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Improve handling of named destinations in out-of-order NameTrees (PR 10274 follow-up)

According to the specification, see https://web.archive.org/web/20210404042322if_/https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G6.2384179, the keys of a NameTree/NumberTree should be ordered.
For corrupt PDF files, which violate this assumption, it's thus possible that trying to lookup a single entry fails.

Previously, in PR 10274, we implemented a fallback that only applies to the "bottom" node of a NameTree/NumberTree, which in general might not actually help for sufficiently corrupt NameTree/NumberTree data.
Instead we remove the current *limited* fallback from `NameOrNumberTree.get`, and defer to the call-site to handle this case explicitly e.g. by using `NameOrNumberTree.getAll` for data where that makes sense. For well-formed documents, these changes should *not* lead to any additional data fetching/parsing.

Finally, as part of these changes, the validation of named destination data is improved in the `Catalog` and a new unit-test is also added.
This commit is contained in:
Jonas Jenwald 2021-05-21 13:58:33 +02:00
parent faf6b10939
commit 8d5689387b
6 changed files with 58 additions and 27 deletions

View file

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { FormatError, info, unreachable, warn } from "../shared/util.js";
import { FormatError, unreachable, warn } from "../shared/util.js";
import { isDict, RefSet } from "./primitives.js";
/**
@ -133,23 +133,6 @@ 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;
}