<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>154201</bug_id>
          <alias>CVE-2016-4623</alias>
          <creation_ts>2016-02-12 15:43:35 -0800</creation_ts>
          <short_desc>JSObject::putByIndexBeyondVectorLengthWithoutAttributes needs to go to the sparse map based on MAX_STORAGE_VECTOR_INDEX</short_desc>
          <delta_ts>2016-07-19 17:27:06 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Filip Pizlo">fpizlo</reporter>
          <assigned_to name="Filip Pizlo">fpizlo</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>ggaren</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1164400</commentid>
    <comment_count>0</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-02-12 15:43:35 -0800</bug_when>
    <thetext>Patch forthcoming.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1164408</commentid>
    <comment_count>1</comment_count>
      <attachid>271241</attachid>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-02-12 15:58:39 -0800</bug_when>
    <thetext>Created attachment 271241
the patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1164410</commentid>
    <comment_count>2</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-02-12 16:07:46 -0800</bug_when>
    <thetext>Landed in http://trac.webkit.org/changeset/196524</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1164587</commentid>
    <comment_count>3</comment_count>
      <attachid>271241</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2016-02-13 15:20:48 -0800</bug_when>
    <thetext>Comment on attachment 271241
the patch

View in context: https://bugs.webkit.org/attachment.cgi?id=271241&amp;action=review

&gt; Source/JavaScriptCore/runtime/StringPrototype.cpp:1208
&gt; +                throwOutOfMemoryError(exec);
&gt; +                return JSValue::encode(jsUndefined());

A few thoughts here:

(1) There are two other places in this function where we might exceed MAX_STORAGE_VECTOR_INDEX. I think we want consistent behavior in those places.

(2) It is unlikely this limit will harm web compatibility. I suspect that total process memory usage at the point of MAX_STORAGE_VECTOR_INDEX is greater than 1GB. Chrome unconditionally kills any process over ~1GB. So does iOS. 

(3) Perhaps a more obvious behavior for web developers would be to prohibit strings larger than MAX_STORAGE_VECTOR_INDEX? ECMAScript specifies that a string can be as large as 134 million GBs, but that is obviously absurd. 

(4) It&apos;s surprising that the array that results from a split can cause problems when the input string to split did not cause problems. I think the length of the array will at worst be equal to the length of the string. (Of course, the array can take up 8X more memory, if it uses one 64bit pointer per 8bit character. Still, surprising that 8X makes the difference between OK and not OK.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1164588</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2016-02-13 15:39:51 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 271241 [details]
&gt; the patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=271241&amp;action=review
&gt; 
&gt; &gt; Source/JavaScriptCore/runtime/StringPrototype.cpp:1208
&gt; &gt; +                throwOutOfMemoryError(exec);
&gt; &gt; +                return JSValue::encode(jsUndefined());
&gt; 
&gt; A few thoughts here:
&gt; 
&gt; (1) There are two other places in this function where we might exceed
&gt; MAX_STORAGE_VECTOR_INDEX. I think we want consistent behavior in those
&gt; places.

I agree.  We should do something for those, too, if we think it was a good idea to do it here.

&gt; 
&gt; (2) It is unlikely this limit will harm web compatibility. I suspect that
&gt; total process memory usage at the point of MAX_STORAGE_VECTOR_INDEX is
&gt; greater than 1GB. Chrome unconditionally kills any process over ~1GB. So
&gt; does iOS. 
&gt; 
&gt; (3) Perhaps a more obvious behavior for web developers would be to prohibit
&gt; strings larger than MAX_STORAGE_VECTOR_INDEX? ECMAScript specifies that a
&gt; string can be as large as 134 million GBs, but that is obviously absurd. 

That&apos;s a good idea.

&gt; 
&gt; (4) It&apos;s surprising that the array that results from a split can cause
&gt; problems when the input string to split did not cause problems. I think the
&gt; length of the array will at worst be equal to the length of the string. (Of
&gt; course, the array can take up 8X more memory, if it uses one 64bit pointer
&gt; per 8bit character. Still, surprising that 8X makes the difference between
&gt; OK and not OK.)

I think that MAX_STORAGE_VECTOR_INDEX is too small right now, which exacerbates the problem.

I wouldn&apos;t be surprised if split() gave an OOME for a very large string because I would assume that the split() has to allocate the array and the substrings. Some developers will realize that the engine should optimize the substrings by either doing the classic substring optimization, but even that will allocate some kind of object. Some developers will realize that the engine should use single-character-string optimizations, but even then we&apos;re still allocating the array. So even if the array takes the same amount of memory as the string, it&apos;s not surprising that you had enough memory for the string but not enough for the array. I don&apos;t think anyone would expect the GC to kill the string the moment that the array was allocated, even if the string was logically dead after the split.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>271241</attachid>
            <date>2016-02-12 15:58:39 -0800</date>
            <delta_ts>2016-02-12 16:04:44 -0800</delta_ts>
            <desc>the patch</desc>
            <filename>blah.patch</filename>
            <type>text/plain</type>
            <size>3495</size>
            <attacher name="Filip Pizlo">fpizlo</attacher>
            
              <data encoding="base64">SW5kZXg6I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3RlY3Qgb3Vyc2VsdmVzLCB3ZSBiYWlsIGF0IHRo
aXMgcG9pbnQuCisgICAgICAgICAgICAgICAgdGhyb3dPdXRPZk1lbW9yeUVycm9yKGV4ZWMpOwor
ICAgICAgICAgICAgICAgIHJldHVybiBKU1ZhbHVlOjplbmNvZGUoanNVbmRlZmluZWQoKSk7Cisg
ICAgICAgICAgICB9CiAKICAgICAgICAgICAgIC8vIDUuIExldCBwID0gZS4KICAgICAgICAgICAg
IC8vIDguIExldCBxID0gcC4K
</data>
<flag name="review"
          id="296067"
          type_id="1"
          status="+"
          setter="saam"
    />
          </attachment>
      

    </bug>

</bugzilla>