From 76f23ce3b5afa2e978c3d90306020d2405a7d27c Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 17 Apr 2025 13:57:30 +0200 Subject: [PATCH 1/2] Catch, and ignore, errors during `Page.prototype.getStructTree` This way any errors thrown during parsing of the page-structTree will not be forwarded to the viewer. --- src/core/document.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/document.js b/src/core/document.js index b1e1caaec..7324c9980 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -707,10 +707,18 @@ class Page { // Ensure that the structTree will contain the page's annotations. await this._parsedAnnotations; - const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [ - structTreeRoot, - ]); - return this.pdfManager.ensure(structTree, "serializable"); + try { + const structTree = await this.pdfManager.ensure( + this, + "_parseStructTree", + [structTreeRoot] + ); + const data = await this.pdfManager.ensure(structTree, "serializable"); + return data; + } catch (ex) { + warn(`getStructTree: "${ex}".`); + return null; + } } /** From bf553f22da96a6e61dfa9b5804af273a6b13852d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 17 Apr 2025 14:01:53 +0200 Subject: [PATCH 2/2] Ensure that the /P-entry is actually a dictionary in `StructTreePage.prototype.addNode` This may fix issue 19822, but without a test-case it's simply impossible to know for sure. --- src/core/struct_tree.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/struct_tree.js b/src/core/struct_tree.js index a8766e92e..59ba40cb6 100644 --- a/src/core/struct_tree.js +++ b/src/core/struct_tree.js @@ -757,7 +757,10 @@ class StructTreePage { const parent = dict.get("P"); - if (!parent || isName(parent.get("Type"), "StructTreeRoot")) { + if ( + !(parent instanceof Dict) || + isName(parent.get("Type"), "StructTreeRoot") + ) { if (!this.addTopLevelNode(dict, element)) { map.delete(dict); }