From 5a774b7ed3addad20bd044890213fe33e469102b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 15 May 2022 11:12:00 +0200 Subject: [PATCH] Adjust the heuristics for handling of incomplete path operators (issue 14917) This limits the heuristics for handling of incomplete path operators, see PR 9838, to only apply to *sequences* of such operators. In practice a couple of invalid path operators are (hopefully) unlikely to completely break rendering, whereas a sequence of them will easily lead to fairly chaotic rendering artifacts. --- src/core/evaluator.js | 11 +++++++++-- test/pdfs/issue14917.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/issue14917.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 68dcab9aa..45cd1a070 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -4765,6 +4765,7 @@ class EvaluatorPreprocessor { }); this.stateManager = stateManager; this.nonProcessedArgs = []; + this._isPathOp = false; this._numInvalidPathOPS = 0; } @@ -4810,6 +4811,13 @@ class EvaluatorPreprocessor { const numArgs = opSpec.numArgs; let argsLength = args !== null ? args.length : 0; + // If the *previous* command wasn't a path operator, reset the heuristic + // used with incomplete path operators below (fixes issue14917.pdf). + if (!this._isPathOp) { + this._numInvalidPathOPS = 0; + } + this._isPathOp = fn >= OPS.moveTo && fn <= OPS.endPath; + if (!opSpec.variableArgs) { // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf if (argsLength !== numArgs) { @@ -4837,8 +4845,7 @@ class EvaluatorPreprocessor { // used to error, rather than just warn, once a number of invalid // path operators have been encountered (fixes bug1443140.pdf). if ( - fn >= OPS.moveTo && - fn <= OPS.endPath && // Path operator + this._isPathOp && ++this._numInvalidPathOPS > EvaluatorPreprocessor.MAX_INVALID_PATH_OPS ) { diff --git a/test/pdfs/issue14917.pdf.link b/test/pdfs/issue14917.pdf.link new file mode 100644 index 000000000..ecc6255c7 --- /dev/null +++ b/test/pdfs/issue14917.pdf.link @@ -0,0 +1 @@ +https://web.archive.org/web/20220515091440/https://pdf.cdn.readpaper.com/spd/2963250244.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 247097f8e..f6a79dcec 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3016,6 +3016,14 @@ }, "about": "Need to test *at least* three pages, since the `GlobalImageCache` is involved." }, + { "id": "issue14917", + "file": "pdfs/issue14917.pdf", + "md5": "12201b35853f78a501ac46b91608f8b6", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "issue1127-text", "file": "pdfs/issue1127.pdf", "md5": "4fb2be5ffefeafda4ba977de2a1bb4d8",