From 4aabd063fcf098452829d4601f60920f0fc054a9 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 4 May 2020 16:51:08 +0200 Subject: [PATCH] Gracefully handle annotation parsing errors in `Page.getOperatorList` (issue 11871) This should ensure that a page will always render successfully, even if there's errors during the Annotation fetching/parsing. Additionally the `OperatorList.addOpList` method is also adjusted to ignore invalid data, to make it slightly more robust. --- src/core/document.js | 14 +++++++++----- src/core/operator_list.js | 6 +++++- test/pdfs/issue11871.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/issue11871.pdf.link diff --git a/src/core/document.js b/src/core/document.js index d89bdbe2e..a3846515a 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -302,11 +302,15 @@ class Page { for (const annotation of annotations) { if (isAnnotationRenderable(annotation, intent)) { opListPromises.push( - annotation.getOperatorList( - partialEvaluator, - task, - renderInteractiveForms - ) + annotation + .getOperatorList(partialEvaluator, task, renderInteractiveForms) + .catch(function (reason) { + warn( + "getOperatorList - ignoring annotation data during " + + `"${task.name}" task: "${reason}".` + ); + return null; + }) ); } } diff --git a/src/core/operator_list.js b/src/core/operator_list.js index a086ffad8..0ae08bba5 100644 --- a/src/core/operator_list.js +++ b/src/core/operator_list.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { assert, ImageKind, OPS } from "../shared/util.js"; +import { assert, ImageKind, OPS, warn } from "../shared/util.js"; var QueueOptimizer = (function QueueOptimizerClosure() { function addState(parentState, pattern, checkFn, iterateFn, processFn) { @@ -674,6 +674,10 @@ var OperatorList = (function OperatorListClosure() { }, addOpList(opList) { + if (!(opList instanceof OperatorList)) { + warn('addOpList - ignoring invalid "opList" parameter.'); + return; + } Object.assign(this.dependencies, opList.dependencies); for (var i = 0, ii = opList.length; i < ii; i++) { this.addOp(opList.fnArray[i], opList.argsArray[i]); diff --git a/test/pdfs/issue11871.pdf.link b/test/pdfs/issue11871.pdf.link new file mode 100644 index 000000000..02402da0d --- /dev/null +++ b/test/pdfs/issue11871.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/4575091/bugdoc.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 7e2b7b8fa..e804550d9 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1134,6 +1134,15 @@ "link": true, "type": "eq" }, + { "id": "issue11871", + "file": "pdfs/issue11871.pdf", + "md5": "9c533eacd0ca892df4191360848668a2", + "rounds": 1, + "link": true, + "firstPage": 2, + "lastPage": 2, + "type": "eq" + }, { "id": "bug1252420", "file": "pdfs/bug1252420.pdf", "md5": "f21c911b9b655972b06ef782a1fa6a17",