Bug 1430552 - Handle possible freetype failures in gfxFT2FontBase::GetFTGlyphAdvance to avoid risk of crashes. r=lsalzman

This commit is contained in:
Jonathan Kew 2018-01-15 16:36:47 +00:00
Родитель 41d4da5cef
Коммит e164d9c087
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -511,14 +511,22 @@ FT_Fixed
gfxFT2FontBase::GetFTGlyphAdvance(uint16_t aGID)
{
gfxFT2LockedFace face(this);
MOZ_ASSERT(face.get());
if (!face.get()) {
// Failed to get the FT_Face? Give up already.
return 0;
}
int32_t flags =
gfxPlatform::GetPlatform()->FontHintingEnabled()
? FT_LOAD_ADVANCE_ONLY
: FT_LOAD_ADVANCE_ONLY | FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_HINTING;
FT_Fixed advance = 0;
mozilla::DebugOnly<FT_Error> ftError =
FT_Load_Glyph(face.get(), aGID, flags);
FT_Error ftError = FT_Load_Glyph(face.get(), aGID, flags);
MOZ_ASSERT(!ftError);
if (ftError != FT_Err_Ok) {
// FT_Face was somehow broken/invalid? Don't try to access glyph slot.
return 0;
}
FT_Fixed advance = 0;
if (face.get()->face_flags & FT_FACE_FLAG_SCALABLE) {
advance = face.get()->glyph->linearHoriAdvance;
} else {