From 185be678ec13532daa2e9762b9a08f3948fdcb7d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 25 Jun 2021 15:51:08 +0200 Subject: [PATCH] Check that TrueType (3, 0) cmap tables, for symbolic fonts, are sorted correctly (issue 13626) According to a comment in `readCmapTable`, we're assuming that the cmap tables (when more than one exist) are sorted in ascending order. If that's not the case, keep checking the following cmap tables in order to fix the referenced issue. --- src/core/fonts.js | 13 ++++++++++++- test/pdfs/issue13626.pdf.link | 1 + test/test_manifest.json | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue13626.pdf.link diff --git a/src/core/fonts.js b/src/core/fonts.js index c1f1d2266..b66936532 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -1372,7 +1372,18 @@ class Font { } } else if (isSymbolicFont && platformId === 3 && encodingId === 0) { useTable = true; - canBreak = true; + + let correctlySorted = true; + if (i < numTables - 1) { + const nextBytes = file.peekBytes(2), + nextPlatformId = int16(nextBytes[0], nextBytes[1]); + if (nextPlatformId < platformId) { + correctlySorted = false; + } + } + if (correctlySorted) { + canBreak = true; + } } if (useTable) { diff --git a/test/pdfs/issue13626.pdf.link b/test/pdfs/issue13626.pdf.link new file mode 100644 index 000000000..a4ff2d321 --- /dev/null +++ b/test/pdfs/issue13626.pdf.link @@ -0,0 +1 @@ +https://github.com/mozilla/pdf.js/files/6715502/test.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 7a1a935f9..655c0d756 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1635,6 +1635,13 @@ "rounds": 1, "type": "eq" }, + { "id": "issue13626", + "file": "pdfs/issue13626.pdf", + "md5": "68bc1c2459d56e8c33f5a12a88c9df7d", + "link": true, + "rounds": 1, + "type": "eq" + }, { "id": "simpletype3font-text", "file": "pdfs/simpletype3font.pdf", "md5": "b374c7543920840c61999e9e86939f99",