<?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>153835</bug_id>
          
          <creation_ts>2016-02-03 10:08:05 -0800</creation_ts>
          <short_desc>[WTR] Crash in EventSendingController::contextClick() when context menu event is not handled</short_desc>
          <delta_ts>2016-02-03 23:35:08 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>WebKit Local 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></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>153493</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>darin</cc>
    
    <cc>lforschler</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1161702</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2016-02-03 10:08:05 -0800</bug_when>
    <thetext>WKBundlePageCopyContextMenuAtPointInWindow() returns nullptr when the context menu event is not hanlded, but we are using the returned value without null checking it. This happened in EWS with a new test that will be introduced in bug #153493

CRASHING TEST: fast/events/contextmenu-on-scrollbars.html

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.WebKit              	0x000000010bd528a9 WKArrayGetSize + 9
1   WebKitTestRunnerInjectedBundle	0x00000001172386f7 0x117228000 + 67319
2   com.apple.JavaScriptCore      	0x000000010cf49bab long long JSC::APICallbackFunction::call&lt;JSC::JSCallbackFunction&gt;(JSC::ExecState*) + 571 (APICallbackFunction.h:61)
3   com.apple.JavaScriptCore      	0x000000010d071343 JSC::LLInt::setUpCall(JSC::ExecState*, JSC::Instruction*, JSC::CodeSpecializationKind, JSC::JSValue, JSC::LLIntCallLinkInfo*) + 595 (LLIntSlowPaths.cpp:1110)
4   com.apple.JavaScriptCore      	0x000000010d078157 llint_entry + 23679
5   com.apple.JavaScriptCore      	0x000000010d0722f5 vmEntryToJavaScript + 299
6   com.apple.JavaScriptCore      	0x000000010cefc9ae JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 158 (JITCode.cpp:81)
7   com.apple.JavaScriptCore      	0x000000010ce7b15e JSC::Interpreter::execute(JSC::ProgramExecutable*, JSC::ExecState*, JSC::JSObject*) + 10558 (Interpreter.cpp:972)
8   com.apple.JavaScriptCore      	0x000000010cb27d91 JSC::evaluate(JSC::ExecState*, JSC::SourceCode const&amp;, JSC::JSValue, WTF::NakedPtr&lt;JSC::Exception&gt;&amp;) + 593 (Completion.cpp:105)
9   com.apple.WebCore             	0x000000010e56bef5 WebCore::ScriptController::evaluateInWorld(WebCore::ScriptSourceCode const&amp;, WebCore::DOMWrapperWorld&amp;, WebCore::ExceptionDetails*) + 309 (JSMainThreadExecState.h:80)
10  com.apple.WebCore             	0x000000010e56c140 WebCore::ScriptController::evaluate(WebCore::ScriptSourceCode const&amp;, WebCore::ExceptionDetails*) + 48 (ScriptController.cpp:180)
11  com.apple.WebCore             	0x000000010e5721d4 WebCore::ScriptElement::executeScript(WebCore::ScriptSourceCode const&amp;) + 260 (ScriptElement.cpp:310)
12  com.apple.WebCore             	0x000000010e570ce5 WebCore::ScriptElement::prepareScript(WTF::TextPosition const&amp;, WebCore::ScriptElement::LegacyTypeSupport) + 1061 (StdLibExtras.h:350)
13  com.apple.WebCore             	0x000000010dd591d8 WebCore::HTMLScriptRunner::runScript(WebCore::Element*, WTF::TextPosition const&amp;) + 344 (ScriptElement.h:59)
14  com.apple.WebCore             	0x000000010dd59030 WebCore::HTMLScriptRunner::execute(WTF::PassRefPtr&lt;WebCore::Element&gt;, WTF::TextPosition const&amp;) + 48 (HTMLScriptRunner.cpp:189)
15  com.apple.WebCore             	0x000000010dcf5f86 WebCore::HTMLDocumentParser::runScriptsForPausedTreeBuilder() + 86 (StdLibExtras.h:350)
16  com.apple.WebCore             	0x000000010dcf604d WebCore::HTMLDocumentParser::canTakeNextToken(WebCore::HTMLDocumentParser::SynchronousMode, WebCore::PumpSession&amp;) + 93 (HTMLDocumentParser.cpp:214)
17  com.apple.WebCore             	0x000000010dcf5c40 WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 544 (HTMLDocumentParser.cpp:252)
18  com.apple.WebCore             	0x000000010dcf6990 WebCore::HTMLDocumentParser::append(WTF::RefPtr&lt;WTF::StringImpl&gt;&amp;&amp;) + 736 (DocumentParser.h:71)
19  com.apple.WebCore             	0x000000010da88725 WebCore::DecodedDataDocumentParser::appendBytes(WebCore::DocumentWriter&amp;, char const*, unsigned long) + 117 (StdLibExtras.h:350)
20  com.apple.WebCore             	0x000000010dadd731 WebCore::DocumentLoader::commitData(char const*, unsigned long) + 657 (DocumentLoader.cpp:890)
21  com.apple.WebKit              	0x000000010bc606c6 WebKit::WebFrameLoaderClient::committedLoad(WebCore::DocumentLoader*, char const*, int) + 50
22  com.apple.WebCore             	0x000000010dadf6d1 WebCore::DocumentLoader::commitLoad(char const*, int) + 145 (DocumentLoader.h:229)
23  com.apple.WebCore             	0x000000010d8eaa70 WebCore::CachedRawResource::notifyClientsDataWasReceived(char const*, unsigned int) + 160 (CachedResourceClientWalker.h:51)
24  com.apple.WebCore             	0x000000010d8ea941 WebCore::CachedRawResource::addDataBuffer(WebCore::SharedBuffer&amp;) + 145 (CachedRawResource.cpp:70)
25  com.apple.WebCore             	0x000000010e6b155a WebCore::SubresourceLoader::didReceiveDataOrBuffer(char const*, int, WTF::PassRefPtr&lt;WebCore::SharedBuffer&gt;, long long, WebCore::DataPayloadType) + 218 (SubresourceLoader.cpp:300)
26  com.apple.WebCore             	0x000000010e6b1443 WebCore::SubresourceLoader::didReceiveData(char const*, unsigned int, long long, WebCore::DataPayloadType) + 35 (StdLibExtras.h:350)
27  com.apple.WebKit              	0x000000010bd287ff WebKit::WebResourceLoader::didReceiveWebResourceLoaderMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;) + 291
28  com.apple.WebKit              	0x000000010bafc5bd IPC::Connection::dispatchMessage(std::__1::unique_ptr&lt;IPC::MessageDecoder, std::__1::default_delete&lt;IPC::MessageDecoder&gt; &gt;) + 127
29  com.apple.WebKit              	0x000000010bafecc4 IPC::Connection::dispatchOneMessage() + 126
30  com.apple.JavaScriptCore      	0x000000010d2c9fd5 WTF::RunLoop::performWork() + 437 (functional:1742)
31  com.apple.JavaScriptCore      	0x000000010d2ca382 WTF::RunLoop::performWork(void*) + 34 (RunLoopCF.cpp:39)
32  com.apple.CoreFoundation      	0x00007fff97fa6a01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
33  com.apple.CoreFoundation      	0x00007fff97f98b8d __CFRunLoopDoSources0 + 269
34  com.apple.CoreFoundation      	0x00007fff97f981bf __CFRunLoopRun + 927
35  com.apple.CoreFoundation      	0x00007fff97f97bd8 CFRunLoopRunSpecific + 296
36  com.apple.HIToolbox           	0x00007fff9842856f RunCurrentEventLoopInMode + 235
37  com.apple.HIToolbox           	0x00007fff984282ea ReceiveNextEventCommon + 431
38  com.apple.HIToolbox           	0x00007fff9842812b _BlockUntilNextEventMatchingListInModeWithFilter + 71
39  com.apple.AppKit              	0x00007fff8c4718ab _DPSNextEvent + 978
40  com.apple.AppKit              	0x00007fff8c470e58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
41  com.apple.AppKit              	0x00007fff8c466af3 -[NSApplication run] + 594
42  com.apple.AppKit              	0x00007fff8c3e3244 NSApplicationMain + 1832
43  libxpc.dylib                  	0x00007fff90bb8928 _xpc_objc_main + 793
44  libxpc.dylib                  	0x00007fff90bba030 xpc_main + 490
45  com.apple.WebKit.WebContent.Development	0x000000010bab4e78 main + 422 (XPCServiceMain.mm:114)
46  libdyld.dylib                 	0x00007fff90c0a5c9 start + 1
[reply] [-] Comment 11</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1161703</commentid>
    <comment_count>1</comment_count>
      <attachid>270583</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2016-02-03 10:10:38 -0800</bug_when>
    <thetext>Created attachment 270583
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1161713</commentid>
    <comment_count>2</comment_count>
      <attachid>270583</attachid>
    <who name="Martin Robinson">mrobinson</who>
    <bug_when>2016-02-03 10:30:28 -0800</bug_when>
    <thetext>Comment on attachment 270583
Patch

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

&gt; Tools/ChangeLog:9
&gt; +        the context menu event is not hanlded, but we are using the

Nit: hanlded -&gt; handled

&gt; Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp:558
&gt; -    size_t entriesSize = WKArrayGetSize(menuEntries.get());
&gt; +    size_t entriesSize = menuEntries ? WKArrayGetSize(menuEntries.get()) : 0;

Perhaps better to simply return early in this case?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1161914</commentid>
    <comment_count>3</comment_count>
      <attachid>270583</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2016-02-03 23:04:21 -0800</bug_when>
    <thetext>Comment on attachment 270583
Patch

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

Thanks for the review!

&gt;&gt; Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp:558
&gt;&gt; +    size_t entriesSize = menuEntries ? WKArrayGetSize(menuEntries.get()) : 0;
&gt; 
&gt; Perhaps better to simply return early in this case?

Yes, indeed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1161917</commentid>
    <comment_count>4</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2016-02-03 23:35:08 -0800</bug_when>
    <thetext>Committed r196110: &lt;http://trac.webkit.org/changeset/196110&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>270583</attachid>
            <date>2016-02-03 10:10:38 -0800</date>
            <delta_ts>2016-02-03 10:30:28 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>wtr-context-click-crash.diff</filename>
            <type>text/plain</type>
            <size>1724</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1Rvb2xzL0NoYW5nZUxvZyBiL1Rvb2xzL0NoYW5nZUxvZwppbmRleCA1NjM2
MDA0Li42Mzc2ZmRjIDEwMDY0NAotLS0gYS9Ub29scy9DaGFuZ2VMb2cKKysrIGIvVG9vbHMvQ2hh
bmdlTG9nCkBAIC0xLDMgKzEsMTcgQEAKKzIwMTYtMDItMDMgIENhcmxvcyBHYXJjaWEgQ2FtcG9z
ICA8Y2dhcmNpYUBpZ2FsaWEuY29tPgorCisgICAgICAgIFtXVFJdIENyYXNoIGluIEV2ZW50U2Vu
ZGluZ0NvbnRyb2xsZXI6OmNvbnRleHRDbGljaygpIHdoZW4gY29udGV4dCBtZW51IGV2ZW50IGlz
IG5vdCBoYW5kbGVkCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNn
aT9pZD0xNTM4MzUKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAg
ICAgICBXS0J1bmRsZVBhZ2VDb3B5Q29udGV4dE1lbnVBdFBvaW50SW5XaW5kb3coKSByZXR1cm5z
IG51bGxwdHIgd2h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b2xsZXI6OmNvbnRleHRDbGljaygpCiAjZW5kaWYKICAgICBKU1ZhbHVlUmVmIGFycmF5
UmVzdWx0ID0gSlNPYmplY3RNYWtlQXJyYXkoY29udGV4dCwgMCwgMCwgMCk7CiAgICAgSlNPYmpl
Y3RSZWYgYXJyYXlPYmogPSBKU1ZhbHVlVG9PYmplY3QoY29udGV4dCwgYXJyYXlSZXN1bHQsIDAp
OwotICAgIHNpemVfdCBlbnRyaWVzU2l6ZSA9IFdLQXJyYXlHZXRTaXplKG1lbnVFbnRyaWVzLmdl
dCgpKTsKKyAgICBzaXplX3QgZW50cmllc1NpemUgPSBtZW51RW50cmllcyA/IFdLQXJyYXlHZXRT
aXplKG1lbnVFbnRyaWVzLmdldCgpKSA6IDA7CiAgICAgZm9yIChzaXplX3QgaSA9IDA7IGkgPCBl
bnRyaWVzU2l6ZTsgKytpKSB7CiAgICAgICAgIEFTU0VSVChXS0dldFR5cGVJRChXS0FycmF5R2V0
SXRlbUF0SW5kZXgobWVudUVudHJpZXMuZ2V0KCksIGkpKSA9PSBXS0NvbnRleHRNZW51SXRlbUdl
dFR5cGVJRCgpKTsKIAo=
</data>
<flag name="review"
          id="295417"
          type_id="1"
          status="+"
          setter="mrobinson"
    />
          </attachment>
      

    </bug>

</bugzilla>