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

Support destinations in NameTrees with encoded keys (issue 14847)

Initially I considered updating the `NameOrNumberTree`-implementation to handle encoded keys, however that quickly became somewhat messy (especially in the `NameOrNumberTree.get`-method) since only NameTrees using string-keys.
Hence the easiest solution, as far as I'm concerned, was thus to just update the `Catalog.destinations`-getter instead. Please note that in the referenced PDF document the `Catalog.destination`-method will thus fallback to fetch all destinations, which should be fine since this is the very first case of encoded keys that we've seen.

Also changes the `NameOrNumberTree.getAll`-method to prevent a possible run-time error, although we've so far not seen such a case, for any non-Array Kids-entries found in a NameTree/NumberTree.

Finally, to improve overall consistency and to hopefully prevent future bugs, the patch also updates a couple of other `NameTree` call-sites to correctly handle encoded keys. (Note that the `Catalog.attachments`-getter was already doing this.)
This commit is contained in:
Jonas Jenwald 2022-04-27 10:34:31 +02:00
parent 981cd5bbfc
commit 71370d012b
5 changed files with 24 additions and 6 deletions

View file

@ -48,8 +48,10 @@ class NameOrNumberTree {
}
if (obj.has("Kids")) {
const kids = obj.get("Kids");
for (let i = 0, ii = kids.length; i < ii; i++) {
const kid = kids[i];
if (!Array.isArray(kids)) {
continue;
}
for (const kid of kids) {
if (processed.has(kid)) {
throw new FormatError(`Duplicate entry in "${this._type}" tree.`);
}
@ -103,7 +105,7 @@ class NameOrNumberTree {
} else if (key > xref.fetchIfRef(limits[1])) {
l = m + 1;
} else {
kidsOrEntries = xref.fetchIfRef(kids[m]);
kidsOrEntries = kid;
break;
}
}