1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #19824 from Snuffleupagus/getStructTree-catch-errors

Improve error handling when parsing page-structTrees
This commit is contained in:
Jonas Jenwald 2025-04-17 15:21:55 +02:00 committed by GitHub
commit f1e20cd668
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View file

@ -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;
}
}
/**

View file

@ -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);
}