Skip to content

Commit

Permalink
Improve the handling of errors, in PartialEvaluator.loadFont, occur…
Browse files Browse the repository at this point in the history
…ing in `PartialEvaluator.preEvaluateFont` (issue 12823)

Currently any errors thrown in `preEvaluateFont`, which is a *synchronous* method, will not be handled at all in the `loadFont` method and we were thus failing to return an `ErrorFont`-instance as intended here.

Also, add an *explicit* check in `PartialEvaluator.preEvaluateFont` to ensure that Type0-fonts always have a *valid* dictionary.
  • Loading branch information
Snuffleupagus committed Jan 7, 2021
1 parent ed3758f commit 6c0e421
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,13 @@ class PartialEvaluator {

var fontCapability = createPromiseCapability();

var preEvaluatedFont = this.preEvaluateFont(font);
let preEvaluatedFont;
try {
preEvaluatedFont = this.preEvaluateFont(font);
} catch (reason) {
warn(`loadFont - ignoring preEvaluatedFont errors: "${reason}".`);
return errorFont();
}
const { descriptor, hash } = preEvaluatedFont;

var fontRefIsRef = isRef(fontRef),
Expand Down Expand Up @@ -3258,6 +3264,9 @@ class PartialEvaluator {
}
dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;

if (!(dict instanceof Dict)) {
throw new FormatError("Descendant font is not a dictionary.");
}
type = dict.get("Subtype");
if (!isName(type)) {
throw new FormatError("invalid font Subtype");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
!issue8570.pdf
!issue8697.pdf
!issue8702.pdf
!issue12823.pdf
!issue8707.pdf
!issue8798r.pdf
!issue8823.pdf
Expand Down
Binary file added test/pdfs/issue12823.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,12 @@
"link": false,
"type": "eq"
},
{ "id": "issue12823",
"file": "pdfs/issue12823.pdf",
"md5": "8391c63006ccc4b41c95de5e8c38deeb",
"rounds": 1,
"type": "eq"
},
{ "id": "bug1050040",
"file": "pdfs/bug1050040.pdf",
"md5": "9076b29bd157e2646b457f29a4472a07",
Expand Down

0 comments on commit 6c0e421

Please sign in to comment.