<!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>[243640] trunk/Source/WebKit</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/243640">243640</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2019-03-28 21:57:11 -0700 (Thu, 28 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>CFDictionary encoder crashes on non-string keys.
https://bugs.webkit.org/show_bug.cgi?id=196388
rdar://problem/49339242

Reviewed by Ryosuke Niwa.

Allow non-string keys in CFDictionary encoding/decoding. Encode the correct
size for dictionaries and arrays when unknown keys or values are skipped.
Allow null array encoding and decoding like dictionary already allowed.

* Shared/cf/ArgumentCodersCF.cpp:
(IPC::encode):
(IPC::decode):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedcfArgumentCodersCFcpp">trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (243639 => 243640)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-03-29 04:42:42 UTC (rev 243639)
+++ trunk/Source/WebKit/ChangeLog       2019-03-29 04:57:11 UTC (rev 243640)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2019-03-28  Timothy Hatcher  <timothy@apple.com>
+
+        CFDictionary encoder crashes on non-string keys.
+        https://bugs.webkit.org/show_bug.cgi?id=196388
+        rdar://problem/49339242
+
+        Reviewed by Ryosuke Niwa.
+
+        Allow non-string keys in CFDictionary encoding/decoding. Encode the correct
+        size for dictionaries and arrays when unknown keys or values are skipped.
+        Allow null array encoding and decoding like dictionary already allowed.
+
+        * Shared/cf/ArgumentCodersCF.cpp:
+        (IPC::encode):
+        (IPC::decode):
+
</ins><span class="cx"> 2019-03-28  John Wilander  <wilander@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Resource Load Statistics: IPC to the WebsiteDataStore in the UI process from NetworkProcess::deleteWebsiteDataForRegistrableDomains()
</span></span></pre></div>
<a id="trunkSourceWebKitSharedcfArgumentCodersCFcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp (243639 => 243640)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp       2019-03-29 04:42:42 UTC (rev 243639)
+++ trunk/Source/WebKit/Shared/cf/ArgumentCodersCF.cpp  2019-03-29 04:57:11 UTC (rev 243640)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "DataReference.h"
</span><span class="cx"> #include "Decoder.h"
</span><span class="cx"> #include "Encoder.h"
</span><ins>+#include <wtf/HashSet.h>
</ins><span class="cx"> #include <wtf/ProcessPrivilege.h>
</span><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx"> #include <wtf/cf/CFURLExtras.h>
</span><span class="lines">@@ -326,16 +327,31 @@
</span><span class="cx"> 
</span><span class="cx"> void encode(Encoder& encoder, CFArrayRef array)
</span><span class="cx"> {
</span><ins>+    if (!array) {
+        encoder << true;
+        return;
+    }
+
+    encoder << false;
+
</ins><span class="cx">     CFIndex size = CFArrayGetCount(array);
</span><span class="cx">     Vector<CFTypeRef, 32> values(size);
</span><span class="cx"> 
</span><span class="cx">     CFArrayGetValues(array, CFRangeMake(0, size), values.data());
</span><span class="cx"> 
</span><del>-    encoder << static_cast<uint64_t>(size);
</del><ins>+    HashSet<CFIndex> invalidIndicies;
+    for (CFIndex i = 0; i < size; ++i) {
+        // Ignore values we don't support.
+        ASSERT(typeFromCFTypeRef(values[i]) != Unknown);
+        if (typeFromCFTypeRef(values[i]) == Unknown)
+            invalidIndicies.add(i);
+    }
</ins><span class="cx"> 
</span><ins>+    encoder << static_cast<uint64_t>(size - invalidIndicies.size());
+
</ins><span class="cx">     for (CFIndex i = 0; i < size; ++i) {
</span><del>-        ASSERT(values[i]);
-
</del><ins>+        if (invalidIndicies.contains(i))
+            continue;
</ins><span class="cx">         encode(encoder, values[i]);
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -342,6 +358,15 @@
</span><span class="cx"> 
</span><span class="cx"> bool decode(Decoder& decoder, RetainPtr<CFArrayRef>& result)
</span><span class="cx"> {
</span><ins>+    bool isNull = false;
+    if (!decoder.decode(isNull))
+        return false;
+
+    if (isNull) {
+        result = nullptr;
+        return true;
+    }
+
</ins><span class="cx">     uint64_t size;
</span><span class="cx">     if (!decoder.decode(size))
</span><span class="cx">         return false;
</span><span class="lines">@@ -414,6 +439,7 @@
</span><span class="cx">         encoder << true;
</span><span class="cx">         return;
</span><span class="cx">     }
</span><ins>+
</ins><span class="cx">     encoder << false;
</span><span class="cx"> 
</span><span class="cx">     CFIndex size = CFDictionaryGetCount(dictionary);
</span><span class="lines">@@ -422,18 +448,25 @@
</span><span class="cx">     
</span><span class="cx">     CFDictionaryGetKeysAndValues(dictionary, keys.data(), values.data());
</span><span class="cx"> 
</span><del>-    encoder << static_cast<uint64_t>(size);
-
</del><ins>+    HashSet<CFTypeRef> invalidKeys;
</ins><span class="cx">     for (CFIndex i = 0; i < size; ++i) {
</span><span class="cx">         ASSERT(keys[i]);
</span><del>-        ASSERT(CFGetTypeID(keys[i]) == CFStringGetTypeID());
</del><span class="cx">         ASSERT(values[i]);
</span><span class="cx"> 
</span><del>-        // Ignore values we don't recognize.
-        if (typeFromCFTypeRef(values[i]) == Unknown)
</del><ins>+        // Ignore keys/values we don't support.
+        ASSERT(typeFromCFTypeRef(keys[i]) != Unknown);
+        ASSERT(typeFromCFTypeRef(values[i]) != Unknown);
+        if (typeFromCFTypeRef(keys[i]) == Unknown || typeFromCFTypeRef(values[i]) == Unknown)
+            invalidKeys.add(keys[i]);
+    }
+
+    encoder << static_cast<uint64_t>(size - invalidKeys.size());
+
+    for (CFIndex i = 0; i < size; ++i) {
+        if (invalidKeys.contains(keys[i]))
</ins><span class="cx">             continue;
</span><span class="cx"> 
</span><del>-        encode(encoder, static_cast<CFStringRef>(keys[i]));
</del><ins>+        encode(encoder, keys[i]);
</ins><span class="cx">         encode(encoder, values[i]);
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -443,6 +476,7 @@
</span><span class="cx">     bool isNull = false;
</span><span class="cx">     if (!decoder.decode(isNull))
</span><span class="cx">         return false;
</span><ins>+
</ins><span class="cx">     if (isNull) {
</span><span class="cx">         result = nullptr;
</span><span class="cx">         return true;
</span><span class="lines">@@ -454,8 +488,7 @@
</span><span class="cx"> 
</span><span class="cx">     RetainPtr<CFMutableDictionaryRef> dictionary = adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
</span><span class="cx">     for (uint64_t i = 0; i < size; ++i) {
</span><del>-        // Try to decode the key name.
-        RetainPtr<CFStringRef> key;
</del><ins>+        RetainPtr<CFTypeRef> key;
</ins><span class="cx">         if (!decode(decoder, key))
</span><span class="cx">             return false;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>