⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 236254 in webkit


Ignore:
Timestamp:
Sep 20, 2018, 2:00:15 AM (8 years ago)
Author:
Simon Fraser
Message:

Fix crash under FontCache::purgeInactiveFontData() when a memory warning fires
https://bugs.webkit.org/show_bug.cgi?id=189722
rdar://problem/44182860

Reviewed by Myles C. Maxfield.

Hashing of FontPlatformData for cachedFonts() is somewhat broken because CFEqual() on CTFont
can return false when the fonts are actually the same, and have the same CFHash(). This
can result in multiple entries in cachedFonts() with the same Font.

Then in FontCache::purgeInactiveFontData(), the loop that appends fonts to fontsToDelete
gets the value by reference, and WTFMoves it into fontsToDelete. This nulls out all
the entries sharing the same value, leaving null entries in the hash table.
We later crash at font->hasOneRef() when using one of those null entries.

Fix by making a copy of the RefPtr<Font> in the loop, so the WTFMove doesn't nuke
the hash table entries. The entries will get removed at cachedFonts().remove() lower down.

  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::purgeInactiveFontData):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r236247 r236254  
     12018-09-20  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Fix crash under FontCache::purgeInactiveFontData() when a memory warning fires
     4        https://bugs.webkit.org/show_bug.cgi?id=189722
     5        rdar://problem/44182860
     6
     7        Reviewed by Myles C. Maxfield.
     8       
     9        Hashing of FontPlatformData for cachedFonts() is somewhat broken because CFEqual() on CTFont
     10        can return false when the fonts are actually the same, and have the same CFHash(). This
     11        can result in multiple entries in cachedFonts() with the same Font.
     12       
     13        Then in FontCache::purgeInactiveFontData(), the loop that appends fonts to fontsToDelete
     14        gets the value by reference, and WTFMoves it into fontsToDelete. This nulls out all
     15        the entries sharing the same value, leaving null entries in the hash table.
     16        We later crash at font->hasOneRef() when using one of those null entries.
     17       
     18        Fix by making a copy of the RefPtr<Font> in the loop, so the WTFMove doesn't nuke
     19        the hash table entries. The entries will get removed at cachedFonts().remove() lower down.
     20
     21        * platform/graphics/FontCache.cpp:
     22        (WebCore::FontCache::purgeInactiveFontData):
     23
    1242018-09-20  Antoine Quint  <graouts@apple.com>
    225
  • trunk/Source/WebCore/platform/graphics/FontCache.cpp

    r235862 r236254  
    377377    while (purgeCount) {
    378378        Vector<RefPtr<Font>, 20> fontsToDelete;
    379         for (auto& font : cachedFonts().values()) {
     379        for (auto font : cachedFonts().values()) {
    380380            LOG(Fonts, " trying to purge font %s (has one ref %d)", font->platformData().description().utf8().data(), font->hasOneRef());
    381381            if (!font->hasOneRef())
Note: See TracChangeset for help on using the changeset viewer.