Ensure that Font.charToGlyph won't fail because String.fromCodePoint is given an invalid code point (issue 11768)

*Please note:* This patch on its own is *not* sufficient to address the underlying problem in the referenced issue, hence why no test-case is included since the *actual* bug still needs to be fixed.

As can be seen in the specification, https://tc39.es/ecma262/#sec-string.fromcodepoint, `String.fromCodePoint` will throw a RangeError for invalid code points.

In the event that a CMap, in a composite font, contains invalid data and/or we fail to parse it correctly, it's thus possible that the glyph mapping that we build end up with entires that cause `String.fromCodePoint` to throw and thus `Font.charToGlyph` to break.
If that happens, as is the case in issue 11768, significant portions of a page/document may fail to render which seems very unfortunate.

While this patch doesn't fix the underlying problem, it's hopefully deemed useful not only for the referenced issue but also to prevent similar bugs in the future.
This commit is contained in:
Jonas Jenwald 2020-03-31 23:10:15 +02:00
parent 79a99737a0
commit 87142a635e

View File

@ -3216,10 +3216,14 @@ var Font = (function FontClosure() {
};
}
var fontChar =
typeof fontCharCode === "number"
? String.fromCodePoint(fontCharCode)
: "";
let fontChar = "";
if (typeof fontCharCode === "number") {
if (fontCharCode <= 0x10ffff) {
fontChar = String.fromCodePoint(fontCharCode);
} else {
warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
}
}
var glyph = this.glyphCache[charcode];
if (