<?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>146093</bug_id>
          
          <creation_ts>2015-06-17 19:00:09 -0700</creation_ts>
          <short_desc>Crash under WebCore::DOMWindow::dispatchMessageEventWithOriginCheck attempting to log console message</short_desc>
          <delta_ts>2015-06-18 11:17:44 -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>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joseph Pecoraro">joepeck</reporter>
          <assigned_to name="Joseph Pecoraro">joepeck</assigned_to>
          <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>commit-queue</cc>
    
    <cc>joepeck</cc>
    
    <cc>timothy</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1102752</commentid>
    <comment_count>0</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 19:00:09 -0700</bug_when>
    <thetext>* SUMMARY
Crash under WebCore::DOMWindow::dispatchMessageEventWithOriginCheck attempting to log console message.

* CRASH SNIPPET
Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000008
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   WebCore::PageConsoleClient::addMessage(JSC::MessageSource, JSC::MessageLevel, WTF::String const&amp;, WTF::String const&amp;, unsigned int, unsigned int, WTF::RefPtr&lt;Inspector::ScriptCallStack&gt;&amp;&amp;, JSC::ExecState*, unsigned long) + 288 (PageConsoleClient.cpp:138)
1   WebCore::PageConsoleClient::addMessage(JSC::MessageSource, JSC::MessageLevel, WTF::String const&amp;, WTF::String const&amp;, unsigned int, unsigned int, WTF::RefPtr&lt;Inspector::ScriptCallStack&gt;&amp;&amp;, JSC::ExecState*, unsigned long) + 244 (StdLibExtras.h:337)
2   WebCore::PageConsoleClient::addMessage(JSC::MessageSource, JSC::MessageLevel, WTF::String const&amp;, WTF::RefPtr&lt;Inspector::ScriptCallStack&gt;&amp;&amp;) + 40 (PageConsoleClient.cpp:119)
3   WebCore::DOMWindow::dispatchMessageEventWithOriginCheck(WebCore::SecurityOrigin*, WTF::PassRefPtr&lt;WebCore::Event&gt;, WTF::PassRefPtr&lt;Inspector::ScriptCallStack&gt;) + 928 (DOMWindow.cpp:941)
4   WebCore::DOMWindow::postMessageTimerFired(WebCore::PostMessageTimer&amp;) + 148 (DOMWindow.cpp:931)
5   WebCore::PostMessageTimer::fired() + 24 (DOMWindow.cpp:173)
6   WebCore::ThreadTimers::sharedTimerFiredInternal() + 144 (ThreadTimers.cpp:132)
7   WebCore::timerFired(__CFRunLoopTimer*, void*) + 32 (SharedTimerCF.cpp:82)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102753</commentid>
    <comment_count>1</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 19:00:29 -0700</bug_when>
    <thetext>&lt;rdar://problem/21380687&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102756</commentid>
    <comment_count>2</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 19:03:47 -0700</bug_when>
    <thetext>I was able to reproduce this once, in the debugger, and verify that a caller of DOMWindow::console() was not handling the possible nullptr result.

    PageConsoleClient* DOMWindow::console() const
    {
        if (!isCurrentlyDisplayedInFrame())
            return nullptr;
        return m_frame-&gt;page() ? &amp;m_frame-&gt;page()-&gt;console() : nullptr;
    }

I was unable to reproduce this reliably though. The test where I was able to get it was something like this, in the LayoutTests/http/tests/security/postMessage directory.

&lt;script&gt;
setTimeout(function() {
    var frame = document.getElementById(&quot;iframe-localhost&quot;);
    var frameWindow = frame.contentWindow;
    var postMessageFunction = frameWindow.postMessage;

    console.log(&quot;here0&quot;, frameWindow, postMessage)
    postMessageFunction.call(frameWindow, &quot;message&quot;, &quot;http://www.example.com&quot;);

    setTimeout(function() {
        console.log(&quot;here1&quot;, frameWindow, postMessage)
        postMessageFunction.call(frameWindow, &quot;message&quot;, &quot;http://www.example.com&quot;);
        gc();
    }, 1000);

    setTimeout(function() {        
        frame.parentElement.removeChild(frame);
        console.log(&quot;here2&quot;, frameWindow, postMessage)
        postMessageFunction.call(frameWindow, &quot;message&quot;, &quot;http://www.example.com&quot;);
    }, 2000);

    setTimeout(function() {        
        console.log(&quot;here2&quot;, frameWindow, postMessage)
        postMessageFunction.call(frameWindow, &quot;message&quot;, &quot;http://www.example.com&quot;);
    }, 3000);
}, 0);
&lt;/script&gt;
&lt;iframe src=&quot;http://localhost:8000/security/postMessage/resources/post-message-listener.html&quot; id=&quot;iframe-localhost&quot; width=&quot;800&quot; height=&quot;300&quot; style=&quot;border: 1px solid black;&quot;&gt;&lt;/iframe&gt;

Being unable to reliably reproduce this, and since it is a very straight forward null check, I&apos;m going to go ahead with a patch. If someone wants me to try more for a test, let me know and I&apos;ll spend more time looking into it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102757</commentid>
    <comment_count>3</comment_count>
      <attachid>255061</attachid>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 19:07:24 -0700</bug_when>
    <thetext>Created attachment 255061
[PATCH] Proposed Fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102781</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2015-06-17 19:59:49 -0700</bug_when>
    <thetext>This feels like it should be testable. Perhaps Chris has an idea how?

I would try going a garbage collection after the frame is removed, not before. Also, postMessage is likely red herring, I&apos;d be trying a synchronous test along the lines of what Tim sent you in an e-mail.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102786</commentid>
    <comment_count>5</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 20:20:32 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; This feels like it should be testable. Perhaps Chris has an idea how?
&gt; 
&gt; I would try going a garbage collection after the frame is removed, not
&gt; before. Also, postMessage is likely red herring, I&apos;d be trying a synchronous
&gt; test along the lines of what Tim sent you in an e-mail.

Yep, this is almost identical to the test Tim sent me.

postMessage is what gets us down the DOMWindow::dispatchMessageEventWithOriginCheck path, so I think it is required here?

Though I had reproduced this once, in trying to re-reproduce it I threw in a number of gc() calls using &lt;script src=&quot;/js-test-resources/js-test-pre.js&quot;&gt;&lt;/script&gt; and had no success =(.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102787</commentid>
    <comment_count>6</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2015-06-17 20:22:02 -0700</bug_when>
    <thetext>Oh, the fact that there was a gc() in what I had above was an accident. I had tested a gc after the frame was removed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102977</commentid>
    <comment_count>7</comment_count>
      <attachid>255061</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-18 11:17:38 -0700</bug_when>
    <thetext>Comment on attachment 255061
[PATCH] Proposed Fix

Clearing flags on attachment: 255061

Committed r185712: &lt;http://trac.webkit.org/changeset/185712&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1102978</commentid>
    <comment_count>8</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-18 11:17:44 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>255061</attachid>
            <date>2015-06-17 19:07:24 -0700</date>
            <delta_ts>2015-06-18 11:17:38 -0700</delta_ts>
            <desc>[PATCH] Proposed Fix</desc>
            <filename>crash-fix.patch</filename>
            <type>text/plain</type>
            <size>1976</size>
            <attacher name="Joseph Pecoraro">joepeck</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJDb3JlL0No
YW5nZUxvZwppbmRleCBlYzVkOWMxLi40MDY5M2RiIDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViQ29y
ZS9DaGFuZ2VMb2cKKysrIGIvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTQg
QEAKKzIwMTUtMDYtMTcgIEpvc2VwaCBQZWNvcmFybyAgPHBlY29yYXJvQGFwcGxlLmNvbT4KKwor
ICAgICAgICBDcmFzaCB1bmRlciBXZWJDb3JlOjpET01XaW5kb3c6OmRpc3BhdGNoTWVzc2FnZUV2
ZW50V2l0aE9yaWdpbkNoZWNrIGF0dGVtcHRpbmcgdG8gbG9nIGNvbnNvbGUgbWVzc2FnZQorICAg
ICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTQ2MDkzCisKKyAg
ICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgKiBwYWdlL0RPTVdp
bmRvdy5jcHA6CisgICAgICAgIChXZWJDb3JlOjpET01XaW5kb3c6OmRpc3BhdGNoTWVzc2FnZUV2
ZW50V2l0aE9yaWdpbkNoZWNrKToKKyAgICAgICAgVGhlIGNvbnNvbGU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b1N0cmluZygpICsKLSAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgIi4gUmVjaXBpZW50IGhhcyBvcmlnaW4gIiArIGRvY3VtZW50KCktPnNl
Y3VyaXR5T3JpZ2luKCktPnRvU3RyaW5nKCkgKyAiLlxuIjsKLSAgICAgICAgICAgIGNvbnNvbGUo
KS0+YWRkTWVzc2FnZShNZXNzYWdlU291cmNlOjpTZWN1cml0eSwgTWVzc2FnZUxldmVsOjpFcnJv
ciwgbWVzc2FnZSwgc3RhY2tUcmFjZSk7CisgICAgICAgICAgICBpZiAoUGFnZUNvbnNvbGVDbGll
bnQqIHBhZ2VDb25zb2xlID0gY29uc29sZSgpKSB7CisgICAgICAgICAgICAgICAgU3RyaW5nIG1l
c3NhZ2UgPSBtYWtlU3RyaW5nKCJVbmFibGUgdG8gcG9zdCBtZXNzYWdlIHRvICIsIGludGVuZGVk
VGFyZ2V0T3JpZ2luLT50b1N0cmluZygpLCAiLiBSZWNpcGllbnQgaGFzIG9yaWdpbiAiLCBkb2N1
bWVudCgpLT5zZWN1cml0eU9yaWdpbigpLT50b1N0cmluZygpLCAiLlxuIik7CisgICAgICAgICAg
ICAgICAgcGFnZUNvbnNvbGUtPmFkZE1lc3NhZ2UoTWVzc2FnZVNvdXJjZTo6U2VjdXJpdHksIE1l
c3NhZ2VMZXZlbDo6RXJyb3IsIG1lc3NhZ2UsIHN0YWNrVHJhY2UpOworICAgICAgICAgICAgfQog
ICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICB9CiAgICAgfQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>