From fc59a5f709d8ebaecffc82fb6719ac074c1ebde1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 7 May 2021 11:49:58 +0200 Subject: [PATCH] Take the `W` array into account when computing the hash, in `PartialEvaluator.preEvaluateFont`, for composite fonts (issue 13343) Without this some *composite* fonts may incorrectly end up with matching `hash`es, thus breaking rendering since we'll not actually try to load/parse some of the fonts. *Please note:* Given that the document, in the referenced issue, doesn't embed *any* of its fonts there's no guarantee that it renders correctly in all configurations even with this patch. --- src/core/evaluator.js | 21 +++++++++++++++++++++ test/pdfs/.gitignore | 1 + test/pdfs/issue13343.pdf | Bin 0 -> 2323 bytes test/test_manifest.json | 6 ++++++ 4 files changed, 28 insertions(+) create mode 100644 test/pdfs/issue13343.pdf diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 7f0827116..4cea9d446 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -3620,6 +3620,27 @@ class PartialEvaluator { uint8array = new Uint8Array(new Uint32Array(widths).buffer); hash.update(uint8array); } + + if (composite) { + const compositeWidths = dict.get("W") || baseDict.get("W"); + if (Array.isArray(compositeWidths)) { + const widthsBuf = []; + for (const entry of compositeWidths) { + if (isNum(entry) || isRef(entry)) { + widthsBuf.push(entry.toString()); + } else if (Array.isArray(entry)) { + const subWidthsBuf = []; + for (const element of entry) { + if (isNum(element) || isRef(element)) { + subWidthsBuf.push(element.toString()); + } + } + widthsBuf.push(`[${subWidthsBuf.join()}]`); + } + } + hash.update(widthsBuf.join()); + } + } } return { diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 12fbc208e..ced9fac3f 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -313,6 +313,7 @@ !noembed-eucjp.pdf !noembed-sjis.pdf !vertical.pdf +!issue13343.pdf !ZapfDingbats.pdf !bug878026.pdf !issue1045.pdf diff --git a/test/pdfs/issue13343.pdf b/test/pdfs/issue13343.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e706bacd5a8fcbdc81c2e73a43a68e064bdf3a61 GIT binary patch literal 2323 zcmcgu+iu!G5N%WSWxrxxkdg=2yS}d!MS=jztxW`|sT4((0}F8kHnJBf^e6k!KWKlX zGiz|TRH$tv3^K!bcP?kn&bW5dY+K?($Z9`-egDA(aL68>fE^z*`!X36aOa?^11{a~ zncbUD71%fNNEOUJ&1R_vhn<`-l@824T3s3FWIEOgIKvIO!lh)s!|aYKvRU3&Md_!V z;UnYmlz$cAnMG(5zxGEpNa9BJ40jyW4(H(WwJ<1(RHN|%{N=`FFckEwf^i@)Hfl1tFSM0sNV3 zEBrb=ZxX8(G;7|15E1eX)!lia)#N-KX5}I7&Zg6`n$UT7=&X+tq{18y>)0XG5woxJ zfy#-NhZpfQPQ{Tq=wzH&ktb7~hDmvulj+Z z{R+Pgsa}zy4ECF$7rkUivdIvI9T~1Q?Efet=lf03rw+a>BFbeE`K}b#MhcbqQ#`>L zwAvGqr%1ui5J-~dV^uQoCQh?L!QtEY2M6!olvl~NI<;I4q2n^UJ&s2O1kC<&rl`S! z=OZR%htgmk#Ao{rEoKBOobW-3_%*=V^)MZp~pBzM=?_`+yBD)DsTAmnm& zW{R~rWoGMgQkL!fG)DK?Xl2iHu7-?*@E8_waY5kwt`9?~bOIYZU68)$kXD;I$3Yft ztaC%0Q5!m+W6Rjk1p@onhA#BC_eOYNH`WO*w(JSV+lpCu;Z}SikXwF*!~#@4bRH*T ll{52R(aAD=`7rM=NRZ^4BIL}Ni*s$T6f*Q#t=773v)@c%ZE^qr literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 61f33ff4d..3f27deedb 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -132,6 +132,12 @@ "link": false, "type": "eq" }, + { "id": "issue13343", + "file": "pdfs/issue13343.pdf", + "md5": "f8bf1888839e15254555092c504e1900", + "rounds": 1, + "type": "eq" + }, { "id": "bug921760", "file": "pdfs/bug921760.pdf", "md5": "1aa136d786a65b0d7cce7bdb3c58c6c3",