From 60bd9580e2e24910fc526388615db5ee9c8a4c45 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 13 Jul 2022 10:06:16 +0200 Subject: [PATCH] Ignore invalid /CIDToGIDMap-entries when parsing fonts (issue 15139) In the referenced PDF document the fonts have /CIDToGIDMap-entries that cannot be loaded. Hence, only when `ignoreErrors` is set, we'll now ignore these corrupt /CIDToGIDMap-entries and fallback to simply assume that no such data is available. Given that this is *clearly* a case of a corrupt PDF document, there's no guarantee that this will "fix" things in the general case since a /CIDToGIDMap may be *required* in order for some composite fonts to render correctly. However, attempting to render *something* is surely better than skipping a font altogether. --- src/core/evaluator.js | 13 ++++++++++--- test/pdfs/issue15139.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/pdfs/issue15139.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 213e9b4c1..9684ff218 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -3373,9 +3373,16 @@ class PartialEvaluator { }; } - const cidToGidMap = dict.get("CIDToGIDMap"); - if (cidToGidMap instanceof BaseStream) { - cidToGidBytes = cidToGidMap.getBytes(); + try { + const cidToGidMap = dict.get("CIDToGIDMap"); + if (cidToGidMap instanceof BaseStream) { + cidToGidBytes = cidToGidMap.getBytes(); + } + } catch (ex) { + if (!this.options.ignoreErrors) { + throw ex; + } + warn(`extractDataStructures - ignoring CIDToGIDMap data: "${ex}".`); } } diff --git a/test/pdfs/issue15139.pdf.link b/test/pdfs/issue15139.pdf.link new file mode 100644 index 000000000..2402f5053 --- /dev/null +++ b/test/pdfs/issue15139.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/9137443/sample4a.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 703da1161..1f19ce771 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4980,6 +4980,14 @@ "lastPage": 1, "type": "eq" }, + { "id": "issue15139", + "file": "pdfs/issue15139.pdf", + "md5": "0f2beb6a788d1e47bb9af737f6670493", + "rounds": 1, + "link": true, + "lastPage": 1, + "type": "eq" + }, { "id": "gesamt", "file": "pdfs/gesamt.pdf", "md5": "743aaa6f46ed0a42864f079d632d942e",