<!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>[230418] releases/WebKitGTK/webkit-2.20</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/230418">230418</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2018-04-09 05:59:58 -0700 (Mon, 09 Apr 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/230026">r230026</a> - appendQuotedJSONString stops on arithmetic overflow instead of propagating it upwards
https://bugs.webkit.org/show_bug.cgi?id=183894

Reviewed by Saam Barati.

JSTests:

* stress/json-stringified-overflow.js: Added.
(catch):

Source/JavaScriptCore:

Use the return value of appendQuotedJSONString to fail more gracefully when given a string that is too large to handle.

* runtime/JSONObject.cpp:
(JSC::Stringifier::appendStringifiedValue):

Source/WTF:

appendQuotedJSONString now returns a bool indicating whether it succeeded, instead of silently failing when given a string too large
to fit in 4GB.

* wtf/text/StringBuilder.h:
* wtf/text/StringBuilderJSON.cpp:
(WTF::StringBuilder::appendQuotedJSONString):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit220JSTestsChangeLog">releases/WebKitGTK/webkit-2.20/JSTests/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit220SourceJavaScriptCoreChangeLog">releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit220SourceJavaScriptCoreruntimeJSONObjectcpp">releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/runtime/JSONObject.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit220SourceWTFChangeLog">releases/WebKitGTK/webkit-2.20/Source/WTF/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit220SourceWTFwtftextStringBuilderh">releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilder.h</a></li>
<li><a href="#releasesWebKitGTKwebkit220SourceWTFwtftextStringBuilderJSONcpp">releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilderJSON.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit220JSTestsstressjsonstringifiedoverflowjs">releases/WebKitGTK/webkit-2.20/JSTests/stress/json-stringified-overflow.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit220JSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/JSTests/ChangeLog (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/JSTests/ChangeLog 2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/JSTests/ChangeLog    2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2018-03-28  Robin Morisset  <rmorisset@apple.com>
+
+        appendQuotedJSONString stops on arithmetic overflow instead of propagating it upwards
+        https://bugs.webkit.org/show_bug.cgi?id=183894
+
+        Reviewed by Saam Barati.
+
+        * stress/json-stringified-overflow.js: Added.
+        (catch):
+
</ins><span class="cx"> 2018-03-22  Michael Saboff  <msaboff@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Race Condition in arrayProtoFuncReverse() causes wrong results or crash
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit220JSTestsstressjsonstringifiedoverflowjs"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.20/JSTests/stress/json-stringified-overflow.js (0 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/JSTests/stress/json-stringified-overflow.js                               (rev 0)
+++ releases/WebKitGTK/webkit-2.20/JSTests/stress/json-stringified-overflow.js  2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+try {
+      JSON.stringify("123".padStart(1073741823))
+} catch (e) {}
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit220SourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/ChangeLog (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/ChangeLog   2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/ChangeLog      2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2018-03-28  Robin Morisset  <rmorisset@apple.com>
+
+        appendQuotedJSONString stops on arithmetic overflow instead of propagating it upwards
+        https://bugs.webkit.org/show_bug.cgi?id=183894
+
+        Reviewed by Saam Barati.
+
+        Use the return value of appendQuotedJSONString to fail more gracefully when given a string that is too large to handle.
+
+        * runtime/JSONObject.cpp:
+        (JSC::Stringifier::appendStringifiedValue):
+
</ins><span class="cx"> 2018-03-25  Saam Barati  <sbarati@apple.com>
</span><span class="cx"> 
</span><span class="cx">         r228149 accidentally removed code that resets m_emptyCursor at the end of a GC
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit220SourceJavaScriptCoreruntimeJSONObjectcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/runtime/JSONObject.cpp (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/runtime/JSONObject.cpp      2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/Source/JavaScriptCore/runtime/JSONObject.cpp 2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -357,8 +357,10 @@
</span><span class="cx">     if (value.isString()) {
</span><span class="cx">         const String& string = asString(value)->value(m_exec);
</span><span class="cx">         RETURN_IF_EXCEPTION(scope, StringifyFailed);
</span><del>-        builder.appendQuotedJSONString(string);
-        return StringifySucceeded;
</del><ins>+        if (builder.appendQuotedJSONString(string))
+            return StringifySucceeded;
+        throwOutOfMemoryError(m_exec, scope);
+        return StringifyFailed;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (value.isNumber()) {
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit220SourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/Source/WTF/ChangeLog (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/Source/WTF/ChangeLog      2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/Source/WTF/ChangeLog 2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2018-03-28  Robin Morisset  <rmorisset@apple.com>
+
+        appendQuotedJSONString stops on arithmetic overflow instead of propagating it upwards
+        https://bugs.webkit.org/show_bug.cgi?id=183894
+
+        Reviewed by Saam Barati.
+
+        appendQuotedJSONString now returns a bool indicating whether it succeeded, instead of silently failing when given a string too large
+        to fit in 4GB.
+
+        * wtf/text/StringBuilder.h:
+        * wtf/text/StringBuilderJSON.cpp:
+        (WTF::StringBuilder::appendQuotedJSONString):
+
</ins><span class="cx"> 2018-03-25  Carlos Alberto Lopez Perez  <clopez@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         WebProcess memory monitor: use %zu format specifier for size_t
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit220SourceWTFwtftextStringBuilderh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilder.h (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilder.h       2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilder.h  2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -174,7 +174,7 @@
</span><span class="cx">         append(U16_TRAIL(c));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WTF_EXPORT_PRIVATE void appendQuotedJSONString(const String&);
</del><ins>+    WTF_EXPORT_PRIVATE bool appendQuotedJSONString(const String&);
</ins><span class="cx"> 
</span><span class="cx">     template<unsigned characterCount>
</span><span class="cx">     ALWAYS_INLINE void appendLiteral(const char (&characters)[characterCount]) { append(characters, characterCount - 1); }
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit220SourceWTFwtftextStringBuilderJSONcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilderJSON.cpp (230417 => 230418)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilderJSON.cpp 2018-04-09 12:59:46 UTC (rev 230417)
+++ releases/WebKitGTK/webkit-2.20/Source/WTF/wtf/text/StringBuilderJSON.cpp    2018-04-09 12:59:58 UTC (rev 230418)
</span><span class="lines">@@ -74,16 +74,18 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void StringBuilder::appendQuotedJSONString(const String& string)
</del><ins>+bool StringBuilder::appendQuotedJSONString(const String& string)
</ins><span class="cx"> {
</span><span class="cx">     // Make sure we have enough buffer space to append this string without having
</span><span class="cx">     // to worry about reallocating in the middle.
</span><span class="cx">     // The 2 is for the '"' quotes on each end.
</span><span class="cx">     // The 6 is for characters that need to be \uNNNN encoded.
</span><del>-    Checked<unsigned> stringLength = string.length();
-    Checked<unsigned> maximumCapacityRequired = length();
</del><ins>+    Checked<unsigned, RecordOverflow> stringLength = string.length();
+    Checked<unsigned, RecordOverflow> maximumCapacityRequired = length();
</ins><span class="cx">     maximumCapacityRequired += 2 + stringLength * 6;
</span><del>-    unsigned allocationSize = maximumCapacityRequired.unsafeGet();
</del><ins>+    unsigned allocationSize;
+    if (CheckedState::DidOverflow == maximumCapacityRequired.safeGet(allocationSize))
+        return false;
</ins><span class="cx">     // This max() is here to allow us to allocate sizes between the range [2^31, 2^32 - 2] because roundUpToPowerOfTwo(1<<31 + some int smaller than 1<<31) == 0.
</span><span class="cx">     // FIXME: roundUpToPowerOfTwo should take Checked<unsigned> and abort if it fails to round up.
</span><span class="cx">     // https://bugs.webkit.org/show_bug.cgi?id=176086
</span><span class="lines">@@ -113,6 +115,7 @@
</span><span class="cx">         m_length = output - m_bufferCharacters16;
</span><span class="cx">     }
</span><span class="cx">     ASSERT(m_buffer->length() >= m_length);
</span><ins>+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre>
</div>
</div>

</body>
</html>