<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[281304] releases/WebKitGTK/webkit-2.32</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/281304">281304</a></dd>
<dt>Author</dt> <dd>aperez@igalia.com</dd>
<dt>Date</dt> <dd>2021-08-20 02:22:42 -0700 (Fri, 20 Aug 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/275189">r275189</a> - REGRESSION(<a href="http://trac.webkit.org/projects/webkit/changeset/274992">r274992</a>): Nullptr crash in FontCache::retrieveOrAddCachedFonts
https://bugs.webkit.org/show_bug.cgi?id=223858
<rdar://75883697>

Reviewed by Darin Adler and Ryosuke Niwa.

Source/WebCore:

Stop using a hash as key in the FontCascadeCache. Instead, use HashTraits and use
FontCascadeCacheKey as key.

Test: fonts/font-cache-crash.html

* platform/graphics/FontCache.cpp:
(WebCore::FontCache::retrieveOrAddCachedFonts):
(WTF::FontCascadeCacheKeyHash::hash):
* platform/graphics/FontCache.h:
(WebCore::FontCascadeCacheKey::operator== const):
(WTF::FontCascadeCacheKeyHash::equal):
(WTF::HashTraits<WebCore::FontCascadeCacheKey>::emptyValue):
(WTF::HashTraits<WebCore::FontCascadeCacheKey>::constructDeletedValue):
(WTF::HashTraits<WebCore::FontCascadeCacheKey>::isDeletedValue):

LayoutTests:

Add layout test coverage.

* fonts/font-cache-crash-expected.txt: Added.
* fonts/font-cache-crash.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit232LayoutTestsChangeLog">releases/WebKitGTK/webkit-2.32/LayoutTests/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceWebCoreChangeLog">releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceWebCoreplatformgraphicsFontCachecpp">releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit232SourceWebCoreplatformgraphicsFontCacheh">releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit232LayoutTestsfontsfontcachecrashexpectedtxt">releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash-expected.txt</a></li>
<li><a href="#releasesWebKitGTKwebkit232LayoutTestsfontsfontcachecrashhtml">releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit232LayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/LayoutTests/ChangeLog (281303 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/LayoutTests/ChangeLog     2021-08-20 09:19:45 UTC (rev 281303)
+++ releases/WebKitGTK/webkit-2.32/LayoutTests/ChangeLog        2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2021-03-29  Chris Dumez  <cdumez@apple.com>
+
+        REGRESSION(r274992): Nullptr crash in FontCache::retrieveOrAddCachedFonts
+        https://bugs.webkit.org/show_bug.cgi?id=223858
+        <rdar://75883697>
+
+        Reviewed by Darin Adler and Ryosuke Niwa.
+
+        Add layout test coverage.
+
+        * fonts/font-cache-crash-expected.txt: Added.
+        * fonts/font-cache-crash.html: Added.
+
</ins><span class="cx"> 2021-03-22  Venky Dass  <yaranamavenkataramana@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Nullptr crash in  WebCore::RenderObject::RenderObjectBitfields::isLineBreak() where a NULL check is missing.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232LayoutTestsfontsfontcachecrashexpectedtxt"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash-expected.txt (0 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash-expected.txt                           (rev 0)
+++ releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash-expected.txt      2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+This test passes if it does not crash.
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit232LayoutTestsfontsfontcachecrashhtml"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash.html (0 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash.html                           (rev 0)
+++ releases/WebKitGTK/webkit-2.32/LayoutTests/fonts/font-cache-crash.html      2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+<html lang="en">
+<head>
+<style></style>
+<script>
+  if (window.testRunner)
+    testRunner.dumpAsText();
+
+  onload = () => {
+    internals.settings.setShouldEnableTextAutosizingBoost(true);
+    document.styleSheets[0].insertRule(`:last-child { font-feature-settings: "smcp" on, "c2sc" on, "pcap" off, "c2pc" off, "unic" off, "titl" off; }`);
+    document.styleSheets[0].insertRule(`:last-child { all: inherit; }`);
+    document.styleSheets[0].insertRule(`:first-of-type { zoom: 10; }`);
+    document.body.offsetTop;
+    document.styleSheets[0].insertRule(`* { font-weight: calc(150 + 50); }`);
+    document.body.offsetTop;
+    document.styleSheets[0].insertRule(`* { writing-mode: vertical-lr; }`);
+  };
+</script>
+</head>
+<body>
+<p>This test passes if it does not crash.</p>
+</body>
+</html>
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog (281303 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog  2021-08-20 09:19:45 UTC (rev 281303)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog     2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2021-03-29  Chris Dumez  <cdumez@apple.com>
+
+        REGRESSION(r274992): Nullptr crash in FontCache::retrieveOrAddCachedFonts
+        https://bugs.webkit.org/show_bug.cgi?id=223858
+        <rdar://75883697>
+
+        Reviewed by Darin Adler and Ryosuke Niwa.
+
+        Stop using a hash as key in the FontCascadeCache. Instead, use HashTraits and use
+        FontCascadeCacheKey as key.
+
+        Test: fonts/font-cache-crash.html
+
+        * platform/graphics/FontCache.cpp:
+        (WebCore::FontCache::retrieveOrAddCachedFonts):
+        (WTF::FontCascadeCacheKeyHash::hash):
+        * platform/graphics/FontCache.h:
+        (WebCore::FontCascadeCacheKey::operator== const):
+        (WTF::FontCascadeCacheKeyHash::equal):
+        (WTF::HashTraits<WebCore::FontCascadeCacheKey>::emptyValue):
+        (WTF::HashTraits<WebCore::FontCascadeCacheKey>::constructDeletedValue):
+        (WTF::HashTraits<WebCore::FontCascadeCacheKey>::isDeletedValue):
+
</ins><span class="cx"> 2021-03-29  Ian Gilbert  <iang@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Make a Ref to HTMLPlugInElement when resolving callback
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceWebCoreplatformgraphicsFontCachecpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.cpp (281303 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.cpp    2021-08-20 09:19:45 UTC (rev 281303)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.cpp       2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -403,7 +403,7 @@
</span><span class="cx">     platformPurgeInactiveFontData();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool keysMatch(const FontCascadeCacheKey& a, const FontCascadeCacheKey& b)
</del><ins>+bool operator==(const FontCascadeCacheKey& a, const FontCascadeCacheKey& b)
</ins><span class="cx"> {
</span><span class="cx">     if (a.fontDescriptionKey != b.fontDescriptionKey)
</span><span class="cx">         return false;
</span><span class="lines">@@ -419,6 +419,18 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+unsigned FontCascadeCacheKeyHash::hash(const FontCascadeCacheKey& key)
+{
+    // FIXME: Should hash the key and the family name characters rather than making a hash out of other hashes.
+    Hasher hasher;
+    add(hasher, key.fontDescriptionKey.computeHash());
+    add(hasher, key.fontSelectorId);
+    add(hasher, key.fontSelectorVersion);
+    for (auto& family : key.families)
+        add(hasher, family.isNull() ? 0 : WebCore::FontCascadeDescription::familyNameHash(family));
+    return hasher.hash();
+}
+
</ins><span class="cx"> void FontCache::invalidateFontCascadeCache()
</span><span class="cx"> {
</span><span class="cx">     m_fontCascadeCache.clear();
</span><span class="lines">@@ -443,20 +455,6 @@
</span><span class="cx">     return key;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static unsigned computeFontCascadeCacheHash(const FontCascadeCacheKey& key)
-{
-    // FIXME: Should hash the key and the family name characters rather than making a hash out of other hashes.
-    IntegerHasher hasher;
-    hasher.add(key.fontDescriptionKey.computeHash());
-    hasher.add(key.fontSelectorId);
-    hasher.add(key.fontSelectorVersion);
-    for (unsigned i = 0; i < key.families.size(); ++i) {
-        auto& family = key.families[i];
-        hasher.add(family.isNull() ? 0 : FontCascadeDescription::familyNameHash(family));
-    }
-    return hasher.hash();
-}
-
</del><span class="cx"> void FontCache::pruneUnreferencedEntriesFromFontCascadeCache()
</span><span class="cx"> {
</span><span class="cx">     m_fontCascadeCache.removeIf([](auto& entry) {
</span><span class="lines">@@ -473,10 +471,8 @@
</span><span class="cx"> Ref<FontCascadeFonts> FontCache::retrieveOrAddCachedFonts(const FontCascadeDescription& fontDescription, RefPtr<FontSelector>&& fontSelector)
</span><span class="cx"> {
</span><span class="cx">     auto key = makeFontCascadeCacheKey(fontDescription, fontSelector.get());
</span><del>-
-    unsigned hash = computeFontCascadeCacheHash(key);
-    auto addResult = m_fontCascadeCache.add(hash, nullptr);
-    if (!addResult.isNewEntry && keysMatch(addResult.iterator->value->key, key))
</del><ins>+    auto addResult = m_fontCascadeCache.add(key, nullptr);
+    if (!addResult.isNewEntry)
</ins><span class="cx">         return addResult.iterator->value->fonts.get();
</span><span class="cx"> 
</span><span class="cx">     auto& newEntry = addResult.iterator->value;
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit232SourceWebCoreplatformgraphicsFontCacheh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.h (281303 => 281304)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.h      2021-08-20 09:19:45 UTC (rev 281303)
+++ releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/FontCache.h 2021-08-20 09:22:42 UTC (rev 281304)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> #include <array>
</span><span class="cx"> #include <limits.h>
</span><span class="cx"> #include <wtf/Forward.h>
</span><ins>+#include <wtf/HashTraits.h>
</ins><span class="cx"> #include <wtf/ListHashSet.h>
</span><span class="cx"> #include <wtf/RefPtr.h>
</span><span class="cx"> #include <wtf/Vector.h>
</span><span class="lines">@@ -183,6 +184,8 @@
</span><span class="cx">     unsigned fontSelectorVersion;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+bool operator==(const FontCascadeCacheKey&, const FontCascadeCacheKey&);
+
</ins><span class="cx"> struct FontCascadeCacheEntry {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="lines">@@ -194,9 +197,20 @@
</span><span class="cx">     Ref<FontCascadeFonts> fonts;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-// FIXME: Should make hash traits for FontCascadeCacheKey instead of using a hash as the key (so we hash a hash).
-typedef HashMap<unsigned, std::unique_ptr<FontCascadeCacheEntry>, AlreadyHashed> FontCascadeCache;
</del><ins>+struct FontCascadeCacheKeyHash {
+    static unsigned hash(const WebCore::FontCascadeCacheKey&);
+    static bool equal(const WebCore::FontCascadeCacheKey& a, const WebCore::FontCascadeCacheKey& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = false;
+};
</ins><span class="cx"> 
</span><ins>+struct FontCascadeCacheKeyHashTraits : WTF::GenericHashTraits<WebCore::FontCascadeCacheKey> {
+    static WebCore::FontCascadeCacheKey emptyValue() { return { }; }
+    static void constructDeletedValue(WebCore::FontCascadeCacheKey& slot) { slot.fontSelectorId = std::numeric_limits<unsigned>::max(); }
+    static bool isDeletedValue(const WebCore::FontCascadeCacheKey& slot) { return slot.fontSelectorId == std::numeric_limits<unsigned>::max(); }
+};
+
+using FontCascadeCache = HashMap<FontCascadeCacheKey, std::unique_ptr<FontCascadeCacheEntry>, FontCascadeCacheKeyHash, FontCascadeCacheKeyHashTraits>;
+
</ins><span class="cx"> class FontCache {
</span><span class="cx">     friend class WTF::NeverDestroyed<FontCache>;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>