diff --git a/src/core/catalog.js b/src/core/catalog.js index 3809d1584..0e8247d9b 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -566,7 +566,7 @@ class Catalog { for (const [key, value] of obj.getAll()) { const dest = fetchDestination(value); if (dest) { - dests[key] = dest; + dests[stringToPDFString(key)] = dest; } } } else if (obj instanceof Dict) { @@ -954,7 +954,7 @@ class Catalog { if (!xfaImages) { xfaImages = new Dict(this.xref); } - xfaImages.set(key, value); + xfaImages.set(stringToPDFString(key), value); } } return shadow(this, "xfaImages", xfaImages); @@ -988,7 +988,7 @@ class Catalog { if (obj instanceof Dict && obj.has("JavaScript")) { const nameTree = new NameTree(obj.getRaw("JavaScript"), this.xref); for (const [key, value] of nameTree.getAll()) { - appendIfJavaScriptDict(key, value); + appendIfJavaScriptDict(stringToPDFString(key), value); } } // Append OpenAction "JavaScript" actions, if any, to the JavaScript map. diff --git a/src/core/name_number_tree.js b/src/core/name_number_tree.js index 96089841c..1462675b3 100644 --- a/src/core/name_number_tree.js +++ b/src/core/name_number_tree.js @@ -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; } } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f8579c1ab..c8511d9c6 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -53,6 +53,7 @@ !issue7544.pdf !issue7507.pdf !issue6931_reduced.pdf +!issue14847.pdf !doc_actions.pdf !issue7580.pdf !issue7598.pdf diff --git a/test/pdfs/issue14847.pdf b/test/pdfs/issue14847.pdf new file mode 100644 index 000000000..1b78e2df2 Binary files /dev/null and b/test/pdfs/issue14847.pdf differ diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 9f44d5205..4cf8c7610 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1004,6 +1004,21 @@ describe("api", function () { await loadingTask.destroy(); }); + it("gets a destination, from /Names (NameTree) dictionary with keys using PDFDocEncoding (issue 14847)", async function () { + const loadingTask = getDocument(buildGetDocumentParams("issue14847.pdf")); + const pdfDoc = await loadingTask.promise; + const destination = await pdfDoc.getDestination("index"); + expect(destination).toEqual([ + { num: 10, gen: 0 }, + { name: "XYZ" }, + 85.039, + 728.504, + null, + ]); + + await loadingTask.destroy(); + }); + it("gets non-string destination", async function () { let numberPromise = pdfDocument.getDestination(4.3); let booleanPromise = pdfDocument.getDestination(true);