<!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>[168295] releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore</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/168295">168295</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-05-05 10:41:58 -0700 (Mon, 05 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/167336">r167336</a> - compileMakeRope does not emit necessary bounds checks
https://bugs.webkit.org/show_bug.cgi?id=130684
&lt;rdar://problem/16398388&gt;

Reviewed by Oliver Hunt.

Add string length bounds checks in a bunch of places. We should never allow a string
to have a length greater than 2^31-1 because it's not clear that the language has
semantics for it and because there is code that assumes that this cannot happen.

Also add a bunch of tests to that effect to cover the various ways in which this was
previously allowed to happen.

* dfg/DFGOperations.cpp:
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileMakeRope):
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::compileMakeRope):
* runtime/JSString.cpp:
(JSC::JSRopeString::RopeBuilder::expand):
* runtime/JSString.h:
(JSC::JSString::create):
(JSC::JSRopeString::RopeBuilder::append):
(JSC::JSRopeString::RopeBuilder::release):
(JSC::JSRopeString::append):
* runtime/Operations.h:
(JSC::jsString):
(JSC::jsStringFromRegisterArray):
(JSC::jsStringFromArguments):
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncIndexOf):
(JSC::stringProtoFuncSlice):
(JSC::stringProtoFuncSubstring):
(JSC::stringProtoFuncToLowerCase):
* tests/stress/make-large-string-jit-strcat.js: Added.
(foo):
* tests/stress/make-large-string-jit.js: Added.
(foo):
* tests/stress/make-large-string-strcat.js: Added.
* tests/stress/make-large-string.js: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreChangeLog">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARMh">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM.h</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARM64h">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARMv7h">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoredfgDFGOperationscpp">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGOperations.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoredfgDFGSpeculativeJITcpp">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeJSStringcpp">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeJSStringh">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.h</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeOperationsh">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/Operations.h</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeStringPrototypecpp">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/StringPrototype.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjitstrcatjs">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit-strcat.js</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjitjs">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit.js</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringstrcatjs">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-strcat.js</a></li>
<li><a href="#releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjs">releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/ChangeLog (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/ChangeLog        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/ChangeLog        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2014-04-15  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        compileMakeRope does not emit necessary bounds checks
+        https://bugs.webkit.org/show_bug.cgi?id=130684
+        &lt;rdar://problem/16398388&gt;
+
+        Reviewed by Oliver Hunt.
+        
+        Add string length bounds checks in a bunch of places. We should never allow a string
+        to have a length greater than 2^31-1 because it's not clear that the language has
+        semantics for it and because there is code that assumes that this cannot happen.
+        
+        Also add a bunch of tests to that effect to cover the various ways in which this was
+        previously allowed to happen.
+
+        * dfg/DFGOperations.cpp:
+        * dfg/DFGSpeculativeJIT.cpp:
+        (JSC::DFG::SpeculativeJIT::compileMakeRope):
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::compileMakeRope):
+        * runtime/JSString.cpp:
+        (JSC::JSRopeString::RopeBuilder::expand):
+        * runtime/JSString.h:
+        (JSC::JSString::create):
+        (JSC::JSRopeString::RopeBuilder::append):
+        (JSC::JSRopeString::RopeBuilder::release):
+        (JSC::JSRopeString::append):
+        * runtime/Operations.h:
+        (JSC::jsString):
+        (JSC::jsStringFromRegisterArray):
+        (JSC::jsStringFromArguments):
+        * runtime/StringPrototype.cpp:
+        (JSC::stringProtoFuncIndexOf):
+        (JSC::stringProtoFuncSlice):
+        (JSC::stringProtoFuncSubstring):
+        (JSC::stringProtoFuncToLowerCase):
+        * tests/stress/make-large-string-jit-strcat.js: Added.
+        (foo):
+        * tests/stress/make-large-string-jit.js: Added.
+        (foo):
+        * tests/stress/make-large-string-strcat.js: Added.
+        * tests/stress/make-large-string.js: Added.
+
</ins><span class="cx"> 2014-03-12  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Update type of local vars to match the type of String length.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARMh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM.h (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM.h        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM.h        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -751,6 +751,11 @@
</span><span class="cx">         return Jump(m_assembler.jmp(ARMCondition(cond)));
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    Jump branchAdd32(ResultCondition cond, Address src, RegisterID dest)
+    {
+        load32(src, ARMRegisters::S0);
+        return branchAdd32(cond, dest, ARMRegisters::S0, dest);
+    }
</ins><span class="cx">     void mull32(RegisterID op1, RegisterID op2, RegisterID dest)
</span><span class="cx">     {
</span><span class="cx">         if (op2 == dest) {
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARM64h"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARM64.h        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -1809,6 +1809,12 @@
</span><span class="cx">         return branchAdd32(cond, op1, dataTempRegister, dest);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    Jump branchAdd32(ResultCondition cond, Address src, RegisterID dest)
+    {
+        load32(src, getCachedDataTempRegisterIDAndInvalidate());
+        return branchAdd32(cond, dest, dataTempRegister, dest);
+    }
+
</ins><span class="cx">     Jump branchAdd32(ResultCondition cond, RegisterID src, RegisterID dest)
</span><span class="cx">     {
</span><span class="cx">         return branchAdd32(cond, dest, src, dest);
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreassemblerMacroAssemblerARMv7h"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/assembler/MacroAssemblerARMv7.h        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -1480,6 +1480,12 @@
</span><span class="cx">         return branchAdd32(cond, dest, src, dest);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    Jump branchAdd32(ResultCondition cond, Address src, RegisterID dest)
+    {
+        load32(src, dataTempRegister);
+        return branchAdd32(cond, dest, dataTempRegister, dest);
+    }
+
</ins><span class="cx">     Jump branchAdd32(ResultCondition cond, TrustedImm32 imm, RegisterID dest)
</span><span class="cx">     {
</span><span class="cx">         return branchAdd32(cond, dest, imm, dest);
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoredfgDFGOperationscpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGOperations.cpp (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGOperations.cpp        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGOperations.cpp        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -966,6 +966,11 @@
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     NativeCallFrameTracer tracer(&amp;vm, exec);
</span><ins>+    
+    if (static_cast&lt;int32_t&gt;(left-&gt;length() + right-&gt;length()) &lt; 0) {
+        throwOutOfMemoryError(exec);
+        return 0;
+    }
</ins><span class="cx"> 
</span><span class="cx">     return JSRopeString::create(vm, left, right);
</span><span class="cx"> }
</span><span class="lines">@@ -975,6 +980,14 @@
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     NativeCallFrameTracer tracer(&amp;vm, exec);
</span><span class="cx"> 
</span><ins>+    Checked&lt;int32_t, RecordOverflow&gt; length = a-&gt;length();
+    length += b-&gt;length();
+    length += c-&gt;length();
+    if (length.hasOverflowed()) {
+        throwOutOfMemoryError(exec);
+        return 0;
+    }
+
</ins><span class="cx">     return JSRopeString::create(vm, a, b, c);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoredfgDFGSpeculativeJITcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -2738,12 +2738,28 @@
</span><span class="cx">         m_jit.storePtr(TrustedImmPtr(0), JITCompiler::Address(resultGPR, JSRopeString::offsetOfFibers() + sizeof(WriteBarrier&lt;JSString&gt;) * i));
</span><span class="cx">     m_jit.load32(JITCompiler::Address(opGPRs[0], JSString::offsetOfFlags()), scratchGPR);
</span><span class="cx">     m_jit.load32(JITCompiler::Address(opGPRs[0], JSString::offsetOfLength()), allocatorGPR);
</span><ins>+    if (!ASSERT_DISABLED) {
+        JITCompiler::Jump ok = m_jit.branch32(
+            JITCompiler::GreaterThanOrEqual, allocatorGPR, TrustedImm32(0));
+        m_jit.breakpoint();
+        ok.link(&amp;m_jit);
+    }
</ins><span class="cx">     for (unsigned i = 1; i &lt; numOpGPRs; ++i) {
</span><span class="cx">         m_jit.and32(JITCompiler::Address(opGPRs[i], JSString::offsetOfFlags()), scratchGPR);
</span><del>-        m_jit.add32(JITCompiler::Address(opGPRs[i], JSString::offsetOfLength()), allocatorGPR);
</del><ins>+        speculationCheck(
+            Uncountable, JSValueSource(), nullptr,
+            m_jit.branchAdd32(
+                JITCompiler::Overflow,
+                JITCompiler::Address(opGPRs[i], JSString::offsetOfLength()), allocatorGPR));
</ins><span class="cx">     }
</span><span class="cx">     m_jit.and32(JITCompiler::TrustedImm32(JSString::Is8Bit), scratchGPR);
</span><span class="cx">     m_jit.store32(scratchGPR, JITCompiler::Address(resultGPR, JSString::offsetOfFlags()));
</span><ins>+    if (!ASSERT_DISABLED) {
+        JITCompiler::Jump ok = m_jit.branch32(
+            JITCompiler::GreaterThanOrEqual, allocatorGPR, TrustedImm32(0));
+        m_jit.breakpoint();
+        ok.link(&amp;m_jit);
+    }
</ins><span class="cx">     m_jit.store32(allocatorGPR, JITCompiler::Address(resultGPR, JSString::offsetOfLength()));
</span><span class="cx">     
</span><span class="cx">     switch (numOpGPRs) {
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeJSStringcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.cpp (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.cpp        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.cpp        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_index == JSRopeString::s_maxInternalRopeLength);
</span><span class="cx">     JSString* jsString = m_jsString;
</span><ins>+    RELEASE_ASSERT(jsString);
</ins><span class="cx">     m_jsString = jsStringBuilder(&amp;m_vm);
</span><span class="cx">     m_index = 0;
</span><span class="cx">     append(jsString);
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeJSStringh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.h (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.h        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/JSString.h        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
</span><span class="cx">  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
</span><del>- *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
</del><ins>+ *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  *  This library is free software; you can redistribute it and/or
</span><span class="cx">  *  modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -123,7 +123,8 @@
</span><span class="cx">         static JSString* create(VM&amp; vm, PassRefPtr&lt;StringImpl&gt; value)
</span><span class="cx">         {
</span><span class="cx">             ASSERT(value);
</span><del>-            size_t length = value-&gt;length();
</del><ins>+            int32_t length = value-&gt;length();
+            RELEASE_ASSERT(length &gt;= 0);
</ins><span class="cx">             size_t cost = value-&gt;cost();
</span><span class="cx">             JSString* newString = new (NotNull, allocateCell&lt;JSString&gt;(vm.heap)) JSString(vm, value);
</span><span class="cx">             newString-&gt;finishCreation(vm, length, cost);
</span><span class="lines">@@ -225,15 +226,21 @@
</span><span class="cx">             {
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            void append(JSString* jsString)
</del><ins>+            bool append(JSString* jsString)
</ins><span class="cx">             {
</span><span class="cx">                 if (m_index == JSRopeString::s_maxInternalRopeLength)
</span><span class="cx">                     expand();
</span><ins>+                if (static_cast&lt;int32_t&gt;(m_jsString-&gt;length() + jsString-&gt;length()) &lt; 0) {
+                    m_jsString = 0;
+                    return false;
+                }
</ins><span class="cx">                 m_jsString-&gt;append(m_vm, m_index++, jsString);
</span><ins>+                return true;
</ins><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             JSRopeString* release()
</span><span class="cx">             {
</span><ins>+                RELEASE_ASSERT(m_jsString);
</ins><span class="cx">                 JSRopeString* tmp = m_jsString;
</span><span class="cx">                 m_jsString = 0;
</span><span class="cx">                 return tmp;
</span><span class="lines">@@ -283,6 +290,7 @@
</span><span class="cx">         {
</span><span class="cx">             m_fibers[index].set(vm, this, jsString);
</span><span class="cx">             m_length += jsString-&gt;m_length;
</span><ins>+            RELEASE_ASSERT(static_cast&lt;int32_t&gt;(m_length) &gt;= 0);
</ins><span class="cx">             setIs8Bit(is8Bit() &amp;&amp; jsString-&gt;is8Bit());
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeOperationsh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/Operations.h (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/Operations.h        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/Operations.h        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -45,13 +45,13 @@
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx"> 
</span><del>-    unsigned length1 = s1-&gt;length();
</del><ins>+    int32_t length1 = s1-&gt;length();
</ins><span class="cx">     if (!length1)
</span><span class="cx">         return s2;
</span><del>-    unsigned length2 = s2-&gt;length();
</del><ins>+    int32_t length2 = s2-&gt;length();
</ins><span class="cx">     if (!length2)
</span><span class="cx">         return s1;
</span><del>-    if ((length1 + length2) &lt; length1)
</del><ins>+    if ((length1 + length2) &lt; 0)
</ins><span class="cx">         return throwOutOfMemoryError(exec);
</span><span class="cx"> 
</span><span class="cx">     return JSRopeString::create(vm, s1, s2);
</span><span class="lines">@@ -61,9 +61,13 @@
</span><span class="cx"> {
</span><span class="cx">     VM* vm = &amp;exec-&gt;vm();
</span><span class="cx"> 
</span><del>-    unsigned length1 = u1.length();
-    unsigned length2 = u2.length();
-    unsigned length3 = u3.length();
</del><ins>+    int32_t length1 = u1.length();
+    int32_t length2 = u2.length();
+    int32_t length3 = u3.length();
+    
+    if (length1 &lt; 0 || length2 &lt; 0 || length3 &lt; 0)
+        return throwOutOfMemoryError(exec);
+    
</ins><span class="cx">     if (!length1)
</span><span class="cx">         return jsString(exec, jsString(vm, u2), jsString(vm, u3));
</span><span class="cx">     if (!length2)
</span><span class="lines">@@ -71,9 +75,9 @@
</span><span class="cx">     if (!length3)
</span><span class="cx">         return jsString(exec, jsString(vm, u1), jsString(vm, u2));
</span><span class="cx"> 
</span><del>-    if ((length1 + length2) &lt; length1)
</del><ins>+    if ((length1 + length2) &lt; 0)
</ins><span class="cx">         return throwOutOfMemoryError(exec);
</span><del>-    if ((length1 + length2 + length3) &lt; length3)
</del><ins>+    if ((length1 + length2 + length3) &lt; 0)
</ins><span class="cx">         return throwOutOfMemoryError(exec);
</span><span class="cx"> 
</span><span class="cx">     return JSRopeString::create(exec-&gt;vm(), jsString(vm, u1), jsString(vm, u2), jsString(vm, u3));
</span><span class="lines">@@ -84,15 +88,10 @@
</span><span class="cx">     VM* vm = &amp;exec-&gt;vm();
</span><span class="cx">     JSRopeString::RopeBuilder ropeBuilder(*vm);
</span><span class="cx"> 
</span><del>-    unsigned oldLength = 0;
-
</del><span class="cx">     for (unsigned i = 0; i &lt; count; ++i) {
</span><span class="cx">         JSValue v = strings[-static_cast&lt;int&gt;(i)].jsValue();
</span><del>-        ropeBuilder.append(v.toString(exec));
-
-        if (ropeBuilder.length() &lt; oldLength) // True for overflow
</del><ins>+        if (!ropeBuilder.append(v.toString(exec)))
</ins><span class="cx">             return throwOutOfMemoryError(exec);
</span><del>-        oldLength = ropeBuilder.length();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return ropeBuilder.release();
</span><span class="lines">@@ -104,15 +103,10 @@
</span><span class="cx">     JSRopeString::RopeBuilder ropeBuilder(*vm);
</span><span class="cx">     ropeBuilder.append(thisValue.toString(exec));
</span><span class="cx"> 
</span><del>-    unsigned oldLength = 0;
-
</del><span class="cx">     for (unsigned i = 0; i &lt; exec-&gt;argumentCount(); ++i) {
</span><span class="cx">         JSValue v = exec-&gt;argument(i);
</span><del>-        ropeBuilder.append(v.toString(exec));
-
-        if (ropeBuilder.length() &lt; oldLength) // True for overflow
</del><ins>+        if (!ropeBuilder.append(v.toString(exec)))
</ins><span class="cx">             return throwOutOfMemoryError(exec);
</span><del>-        oldLength = ropeBuilder.length();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return ropeBuilder.release();
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoreruntimeStringPrototypecpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/StringPrototype.cpp (168294 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/StringPrototype.cpp        2014-05-05 17:33:08 UTC (rev 168294)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/runtime/StringPrototype.cpp        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -773,6 +773,7 @@
</span><span class="cx">     else {
</span><span class="cx">         unsigned pos;
</span><span class="cx">         int len = s.length();
</span><ins>+        RELEASE_ASSERT(len &gt;= 0);
</ins><span class="cx">         if (a1.isUInt32())
</span><span class="cx">             pos = std::min&lt;uint32_t&gt;(a1.asUInt32(), len);
</span><span class="cx">         else {
</span><span class="lines">@@ -916,6 +917,7 @@
</span><span class="cx">         return throwVMTypeError(exec);
</span><span class="cx">     String s = thisValue.toString(exec)-&gt;value(exec);
</span><span class="cx">     int len = s.length();
</span><ins>+    RELEASE_ASSERT(len &gt;= 0);
</ins><span class="cx"> 
</span><span class="cx">     JSValue a0 = exec-&gt;argument(0);
</span><span class="cx">     JSValue a1 = exec-&gt;argument(1);
</span><span class="lines">@@ -1227,6 +1229,7 @@
</span><span class="cx">     JSValue a0 = exec-&gt;argument(0);
</span><span class="cx">     JSValue a1 = exec-&gt;argument(1);
</span><span class="cx">     int len = jsString-&gt;length();
</span><ins>+    RELEASE_ASSERT(len &gt;= 0);
</ins><span class="cx"> 
</span><span class="cx">     double start = a0.toNumber(exec);
</span><span class="cx">     double end;
</span><span class="lines">@@ -1264,6 +1267,7 @@
</span><span class="cx">     int sSize = s.length();
</span><span class="cx">     if (!sSize)
</span><span class="cx">         return JSValue::encode(sVal);
</span><ins>+    RELEASE_ASSERT(sSize &gt;= 0);
</ins><span class="cx"> 
</span><span class="cx">     StringImpl* ourImpl = s.impl();
</span><span class="cx">     RefPtr&lt;StringImpl&gt; lower = ourImpl-&gt;lower();
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjitstrcatjs"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit-strcat.js (0 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit-strcat.js                                (rev 0)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit-strcat.js        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -0,0 +1,24 @@
</span><ins>+// Like make-large-string-jit.js, but tests MakeRope with three arguments and op_strcat
+// in the DFG and FTL JITs.
+
+var s = &quot;s&quot;;
+
+function foo(a, b) {
+    return &quot;t&quot; + a + b;
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 100000; ++i)
+    foo(&quot;a&quot;, &quot;b&quot;);
+
+try {
+    for (var i = 0; i &lt; 31; ++i)
+        s = foo(s, s);
+    print(&quot;Should not have gotten here.&quot;);
+    print(&quot;String length: &quot; + s.length);
+    throw &quot;Should not have gotten here.&quot;;
+} catch (e) {
+    if (e.message != &quot;Out of memory&quot;)
+        throw &quot;Wrong error: &quot; + e;
+}
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjitjs"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit.js (0 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit.js                                (rev 0)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-jit.js        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+// Like make-large-string.js, but tests MakeRope with two arguments in the DFG and FTL JITs.
+
+var s = &quot;s&quot;;
+
+function foo(a, b) {
+    return a + b;
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 100000; ++i)
+    foo(&quot;a&quot;, &quot;b&quot;);
+
+try {
+    for (var i = 0; i &lt; 31; ++i)
+        s = foo(s, s);
+    print(&quot;Should not have gotten here.&quot;);
+    print(&quot;String length: &quot; + s.length);
+    throw &quot;Should not have gotten here.&quot;;
+} catch (e) {
+    if (e.message != &quot;Out of memory&quot;)
+        throw &quot;Wrong error: &quot; + e;
+}
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringstrcatjs"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-strcat.js (0 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-strcat.js                                (rev 0)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string-strcat.js        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+var s = &quot;s&quot;;
+
+try {
+    for (var i = 0; i &lt; 31; ++i)
+        s = &quot;t&quot; + s + s;
+    print(&quot;Should not have gotten here.&quot;);
+    print(&quot;String length: &quot; + s.length);
+    throw &quot;Should not have gotten here.&quot;;
+} catch (e) {
+    if (e.message != &quot;Out of memory&quot;)
+        throw &quot;Wrong error: &quot; + e;
+}
</ins></span></pre></div>
<a id="releasesWebKitGTKwebkit24SourceJavaScriptCoretestsstressmakelargestringjs"></a>
<div class="addfile"><h4>Added: releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string.js (0 => 168295)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string.js                                (rev 0)
+++ releases/WebKitGTK/webkit-2.4/Source/JavaScriptCore/tests/stress/make-large-string.js        2014-05-05 17:41:58 UTC (rev 168295)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+var s = &quot;s&quot;;
+
+try {
+    for (var i = 0; i &lt; 31; ++i)
+        s = s + s;
+    print(&quot;Should not have gotten here.&quot;);
+    print(&quot;String length: &quot; + s.length);
+    throw &quot;Should not have gotten here.&quot;;
+} catch (e) {
+    if (e.message != &quot;Out of memory&quot;)
+        throw &quot;Wrong error: &quot; + e;
+}
</ins></span></pre>
</div>
</div>

</body>
</html>