From dd816e39169b0fd3390257c1b43fb96f9b87577b Mon Sep 17 00:00:00 2001 From: Russell Brenner Date: Wed, 23 Mar 2011 14:36:13 -0700 Subject: [PATCH] Add defensive code for crash in FontPlatformData bug: 4163318 In FontPlatformData, both 0 and -1 are used as special values for mTypeface. Skia has checks to handle null typefaces, but -1 is a special value (hashTableDeletedFontValue) unique to FontPlatformData. The constructors and operators appear to have the necessary guards, but setupPaint(), uniqueID(), and isFixedPitch() needed some touchup to better handle 0 or -1. There's still the question of whether or not it's appropriate to be calling any of those functions with the typeface set to 0 or -1, so these changes may simply be deflecting the underlying problem, but these changes should guard against the immediate failure. Change-Id: Ib68a64ba6d4eeffbd502f29b68074e38c511a746 --- .../graphics/android/FontPlatformDataAndroid.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp b/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp index 352516bcf..337a94d3d 100644 --- a/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp +++ b/WebCore/platform/graphics/android/FontPlatformDataAndroid.cpp @@ -163,11 +163,15 @@ void FontPlatformData::setupPaint(SkPaint* paint) const if (!(ts > 0)) ts = 12; + if (hashTableDeletedFontValue() == mTypeface) + paint->setTypeface(0); + else + paint->setTypeface(mTypeface); + paint->setAntiAlias(true); paint->setSubpixelText(true); paint->setHinting(SkPaint::kSlight_Hinting); paint->setTextSize(SkFloatToScalar(ts)); - paint->setTypeface(mTypeface); paint->setFakeBoldText(mFakeBold); paint->setTextSkewX(mFakeItalic ? -SK_Scalar1/4 : 0); #ifndef SUPPORT_COMPLEX_SCRIPTS @@ -177,7 +181,10 @@ void FontPlatformData::setupPaint(SkPaint* paint) const uint32_t FontPlatformData::uniqueID() const { - return mTypeface->uniqueID(); + if (hashTableDeletedFontValue() == mTypeface) + return SkTypeface::UniqueID(0); + else + return SkTypeface::UniqueID(mTypeface); } bool FontPlatformData::operator==(const FontPlatformData& a) const @@ -207,7 +214,10 @@ unsigned FontPlatformData::hash() const bool FontPlatformData::isFixedPitch() const { - return mTypeface ? mTypeface->isFixedWidth() : false; + if (mTypeface && (mTypeface != hashTableDeletedFontValue())) + return mTypeface->isFixedWidth(); + else + return false; } HB_FaceRec_* FontPlatformData::harfbuzzFace() const -- 2.11.0