Skip to content

Commit

Permalink
Ensure that the Widths array is parsed correctly in `PartialEvaluat…
Browse files Browse the repository at this point in the history
…or.preEvaluateFont`

Looking at how the `Widths` array is parsed in `PartialEvaluator.extractWidths`, it's clear that the implementation in `PartialEvaluator.preEvaluateFont` is a bit too simplistic. In particular, by only wrapping the data into a TypedArray, there's no attempt to handle *indirect* objects which could potentially lead to a colliding `hash`es being computed.
  • Loading branch information
Snuffleupagus committed May 7, 2021
1 parent 8961625 commit 145fd18
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3608,10 +3608,15 @@ class PartialEvaluator {
hash.update(toUnicode.name);
}

var widths = dict.get("Widths") || baseDict.get("Widths");
if (widths) {
uint8array = new Uint8Array(new Uint32Array(widths).buffer);
hash.update(uint8array);
const widths = dict.get("Widths") || baseDict.get("Widths");
if (Array.isArray(widths)) {
const widthsBuf = [];
for (const entry of widths) {
if (isNum(entry) || isRef(entry)) {
widthsBuf.push(entry.toString());
}
}
hash.update(widthsBuf.join());
}

if (composite) {
Expand Down

0 comments on commit 145fd18

Please sign in to comment.