From 0a2f2382541424726168804be2c90b91381608c6 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 10 Jul 2015 13:22:32 +0200 Subject: Better handling of invalid font tables Specifically when reading files with broken cmap tables, we could get some undeterministic results. We handle this more gracefully by verifying that the offsets are sane and bailing out early if not. This replaces the current pattern throughout the font engine for consistency. This is a back-port of 4a1e5dbade4bab55f39bd368480dcca9a11e4b38 from Qt 5. Change-Id: If4172b9ef0808801c8e27ffaad962535afe572ed Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/gui/text/qfontengine_mac.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/gui/text/qfontengine_mac.mm') diff --git a/src/gui/text/qfontengine_mac.mm b/src/gui/text/qfontengine_mac.mm index ba01f4c6fa..460aa5fd65 100644 --- a/src/gui/text/qfontengine_mac.mm +++ b/src/gui/text/qfontengine_mac.mm @@ -625,7 +625,7 @@ bool QFontEngineMacMulti::canRender(const QChar *string, int len) } QFontEngineMac::QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine) - : fontID(fontID), multiEngine(multiEngine), cmap(0), symbolCMap(false) + : fontID(fontID), multiEngine(multiEngine), cmap(0), symbolCMap(false), cmapSize(0) { fontDef = def; ATSUCreateAndCopyStyle(baseStyle, &style); @@ -747,22 +747,21 @@ bool QFontEngineMac::stringToCMap(const QChar *str, int len, QGlyphLayout *glyph { if (!cmap) { cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p')); - int size = 0; - cmap = getCMap(reinterpret_cast(cmapTable.constData()), cmapTable.size(), &symbolCMap, &size); + cmap = getCMap(reinterpret_cast(cmapTable.constData()), cmapTable.size(), &symbolCMap, &cmapSize); if (!cmap) return false; } if (symbolCMap) { for (int i = 0; i < len; ++i) { unsigned int uc = getChar(str, i, len); - glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc); + glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); if(!glyphs->glyphs[i] && uc < 0x100) - glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); + glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, cmapSize, uc + 0xf000); } } else { for (int i = 0; i < len; ++i) { unsigned int uc = getChar(str, i, len); - glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc); + glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); } } -- cgit v1.2.3