From ddea9a6b040a6965b37821fdc24a8485ee927546 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 28 Dec 2016 00:06:54 +0100 Subject: [PATCH] Improve the handling of `Encoding` dictionary, with `Differences` array, in `PartialEvaluator_preEvaluateFont` I recently happened to look at the code I wrote for PR 5964, which fixed [bug 1157493](https://bugzilla.mozilla.org/show_bug.cgi?id=1157493), and I quickly realized that the solution is way too simplistic. The fact that only using the `length` of a `Differences` array worked seems more like a happy accident for a particular set of font data, but could just as easily be incorrect for other PDF files. Note that in practice, the case where the `Encoding` entry is a regular `Dict` (and not a `Ref` or `Name`) is very rare, hence I don't think that we really need to worry about having to reparse this data. Also, the performance of this code-block is quite a bit better by updating the `hash` with the data from the *entire* `Differences` array, instead of at every loop iteration. --- src/core/evaluator.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 2932523fd..697098812 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2189,11 +2189,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { hash.update(entry.name); } else if (isRef(entry)) { hash.update(entry.toString()); - } else if (isArray(entry)) { // 'Differences' entry. - // Ideally we should check the contents of the array, but to avoid - // parsing it here and then again in |extractDataStructures|, - // we only use the array length for now (fixes bug1157493.pdf). - hash.update(entry.length.toString()); + } else if (isArray(entry)) { + // 'Differences' array (fixes bug1157493.pdf). + var diffLength = entry.length, diffBuf = new Array(diffLength); + + for (var j = 0; j < diffLength; j++) { + var diffEntry = entry[j]; + if (isName(diffEntry)) { + diffBuf[j] = diffEntry.name; + } else if (isNum(diffEntry) || isRef(diffEntry)) { + diffBuf[j] = diffEntry.toString(); + } + } + hash.update(diffBuf.join()); } } }