Skip to content

Commit

Permalink
Cherry-pick a595ddd. rdar://117805319
Browse files Browse the repository at this point in the history
    Adding last resort font to System Font fallback set for PUA characters
    https://bugs.webkit.org/show_bug.cgi?id=264737
    rdar://117805319

    Reviewed by Brent Fulgham.

    Until now, when we are purging inactive font data, we would just clear
    the glyph page cache if we had to purge system fallback font.
    This means that we consider glyph page cache would only point to
    fonts from system fonts fallback.

    When we are handling unicode's in the Private-User-Area (PUA) block,
    we shouldn't fallback to system fonts searching for a font that can render
    it, per spec: https://www.w3.org/TR/css-fonts-4/#char-handling-issues
    Instead, we render the glyph 0 with the last resort font. However, this
    font is just added to the custom font cache, and its font pointer in the
    Glyph Page cache is not cleared during memory pressure.

    We should add this font to the system font fallback set, to make sure
    that the associated font pointer is removed from the glyph page cache
    during memory pressure.

    * LayoutTests/fonts/font-cache-memory-pressure-crash.html: Added.
    * Source/WebCore/platform/graphics/FontCascadeFonts.cpp:
    (WebCore::FontCascadeFonts::glyphDataForVariant):
    * LayoutTests/fonts/font-cache-memory-pressure-crash-expected.txt: Added.

    Canonical link: https://commits.webkit.org/267815.567@safari-7617-branch

Canonical link: https://commits.webkit.org/267815.567@safari-7617.1.17.11-branch
  • Loading branch information
rjepstein committed Nov 14, 2023
1 parent 02f0226 commit 4c66f09
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test passes if it doesn't crash.
undefined
Binary file not shown.
8 changes: 6 additions & 2 deletions Source/WebCore/platform/graphics/FontCascadeFonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,12 @@ GlyphData FontCascadeFonts::glyphDataForVariant(UChar32 character, const FontCas
return loadingResult;
// https://drafts.csswg.org/css-fonts-4/#char-handling-issues
// "If a given character is a Private-Use Area Unicode codepoint, user agents must only match font families named in the font-family list that are not generic families. If none of the families named in the font-family list contain a glyph for that codepoint, user agents must display some form of missing glyph symbol for that character rather than attempting installed font fallback for that codepoint."
if (isPrivateUseAreaCharacter(character))
return GlyphData(0, FontCache::forCurrentThread().lastResortFallbackFont(description).ptr()); // 0 is the font's reserved .notdef glyph
if (isPrivateUseAreaCharacter(character)) {
auto font = FontCache::forCurrentThread().lastResortFallbackFont(description);
GlyphData glyphData(0, font.ptr());
m_systemFallbackFontSet.add(WTFMove(font));
return glyphData; // 0 is the font's reserved .notdef glyph
}

return glyphDataForSystemFallback(character, description, variant, resolvedEmojiPolicy, fallbackVisibility == FallbackVisibility::Invisible);
}
Expand Down

0 comments on commit 4c66f09

Please sign in to comment.