<?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>83712</bug_id>
          
          <creation_ts>2012-04-11 13:11:55 -0700</creation_ts>
          <short_desc>Do not dereference a newly allocated JSArray if it is null</short_desc>
          <delta_ts>2012-04-11 14:05:17 -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>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</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="Benjamin Poulain">benjamin</reporter>
          <assigned_to name="Benjamin Poulain">benjamin</assigned_to>
          <cc>ggaren</cc>
    
    <cc>oliver</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>600527</commentid>
    <comment_count>0</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2012-04-11 13:11:55 -0700</bug_when>
    <thetext>In JSArray::tryCreateUninitialized(), we dereference array: &quot;array-&gt;tryFinishCreationUninitialized&quot;, that looks bad.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>600535</commentid>
    <comment_count>1</comment_count>
      <attachid>136735</attachid>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2012-04-11 13:18:44 -0700</bug_when>
    <thetext>Created attachment 136735
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>600545</commentid>
    <comment_count>2</comment_count>
      <attachid>136735</attachid>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2012-04-11 13:30:40 -0700</bug_when>
    <thetext>Comment on attachment 136735
Patch

The initial allocation of the JSArray must succeed -- if it didn&apos;t we would crash in the constructor.  But also the GC guarantees allocation will work.  tryFinishCreationUninitialized on the jsarray is the bit that may fail, and if it fails that results in a bogus JSArray.  That&apos;s where the try... comes from.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>600566</commentid>
    <comment_count>3</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2012-04-11 13:44:15 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; (From update of attachment 136735 [details])
&gt; The initial allocation of the JSArray must succeed -- if it didn&apos;t we would crash in the constructor.  But also the GC guarantees allocation will work.  tryFinishCreationUninitialized on the jsarray is the bit that may fail, and if it fails that results in a bogus JSArray.  That&apos;s where the try... comes from.

That is a very good thing to know.

So would you agree, all the tests like the following are wrong after JSArray::tryCreateUninitialized()?:
if (!array)
   doSomething()

If so, I&apos;ll remove that in an other patch.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>600568</commentid>
    <comment_count>4</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2012-04-11 13:48:47 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; (In reply to comment #2)
&gt; &gt; (From update of attachment 136735 [details] [details])
&gt; &gt; The initial allocation of the JSArray must succeed -- if it didn&apos;t we would crash in the constructor.  But also the GC guarantees allocation will work.  tryFinishCreationUninitialized on the jsarray is the bit that may fail, and if it fails that results in a bogus JSArray.  That&apos;s where the try... comes from.
&gt; 
&gt; That is a very good thing to know.
&gt; 
&gt; So would you agree, all the tests like the following are wrong after JSArray::tryCreateUninitialized()?:
&gt; if (!array)
&gt;    doSomething()
&gt; 
&gt; If so, I&apos;ll remove that in an other patch.

I don&apos;t understand what you&apos;re asking.

If you mean:

JSArray* array = JSArray::tryCreateUninitialised(..)
if (!array)
   doSomething();

then no, the null check is necessary.

The bit of initialisation that makes it a &quot;try&quot; allocation is:

tryFinishCreationUninitialized(..)

That allocates the array&apos;s backing store.  And that allocation may fail.  If that allocation fails then the total allocation from JSArray::tryCreateUninitialised is invalid.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>600580</commentid>
    <comment_count>5</comment_count>
    <who name="Benjamin Poulain">benjamin</who>
    <bug_when>2012-04-11 14:05:17 -0700</bug_when>
    <thetext>&gt; I don&apos;t understand what you&apos;re asking.
&gt; 
&gt; If you mean:
&gt; 
&gt; JSArray* array = JSArray::tryCreateUninitialised(..)
&gt; if (!array)
&gt;    doSomething();
&gt; 
&gt; then no, the null check is necessary.

Thanks for looking into this. That is exactly what I was wondering about.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>136735</attachid>
            <date>2012-04-11 13:18:44 -0700</date>
            <delta_ts>2012-04-11 13:30:40 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-83712-20120411131843.patch</filename>
            <type>text/plain</type>
            <size>2188</size>
            <attacher name="Benjamin Poulain">benjamin</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTEzODg2CmRpZmYgLS1naXQgYS9Tb3VyY2UvSmF2YVNjcmlw
dENvcmUvQ2hhbmdlTG9nIGIvU291cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwppbmRleCA5
MjQ4YjRjMTFlNDZkMGQ5ODI1MjRmY2ViODk4NmM1ODgwMGQ5ODJjLi41NzQ3NGYzNzViMDhhYzE4
YzIzMGYzYjUyZGQ0YzUzM2VmNjg4NmVhIDEwMDY0NAotLS0gYS9Tb3VyY2UvSmF2YVNjcmlwdENv
cmUvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKQEAgLTEs
NSArMSwyNCBAQAogMjAxMi0wNC0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XRhLCBpbml0aWFsTGVuZ3RoKTsKKyAgICAgICAgaWYg
KEpTQXJyYXkqIGFycmF5ID0gbmV3IChOb3ROdWxsLCBhbGxvY2F0ZUNlbGw8SlNBcnJheT4oZ2xv
YmFsRGF0YS5oZWFwKSkgSlNBcnJheShnbG9iYWxEYXRhLCBzdHJ1Y3R1cmUpKQorICAgICAgICAg
ICAgcmV0dXJuIGFycmF5LT50cnlGaW5pc2hDcmVhdGlvblVuaW5pdGlhbGl6ZWQoZ2xvYmFsRGF0
YSwgaW5pdGlhbExlbmd0aCk7CisgICAgICAgIHJldHVybiAwOwogICAgIH0KIAogICAgIEpTQXJy
YXkqIGFzQXJyYXkoSlNWYWx1ZSk7Cg==
</data>
<flag name="review"
          id="141633"
          type_id="1"
          status="-"
          setter="oliver"
    />
          </attachment>
      

    </bug>

</bugzilla>