<?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>160334</bug_id>
          
          <creation_ts>2016-07-28 23:51:32 -0700</creation_ts>
          <short_desc>Crash with an Invalid Web Process IPC Message ID: WebPageProxy.AttributedStringForCharacterRangeCallback</short_desc>
          <delta_ts>2016-07-29 11:46:30 -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>WebKit2</component>
          <version>WebKit 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="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>andersca</cc>
    
    <cc>ap</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1215505</commentid>
    <comment_count>0</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2016-07-28 23:51:32 -0700</bug_when>
    <thetext>&lt;rdar://problem/27078089&gt;

      50 Safari: invalidMessageFunction(OpaqueWKString const*) &lt;==
        50 WebKit: WebKit::WebProcessPool::didReceiveInvalidMessage(IPC::StringReference const&amp;, IPC::StringReference const&amp;)
          50 WebKit: WebKit::WebProcessProxy::didReceiveInvalidMessage(IPC::Connection&amp;, IPC::StringReference, IPC::StringReference)
            50 WebKit: IPC::Connection::dispatchMessage(std::__1::unique_ptr&lt;IPC::MessageDecoder, std::__1::default_delete&lt;IPC::MessageDecoder&gt; &gt;)
              50 WebKit: IPC::Connection::dispatchOneMessage()
                50 JavaScriptCore: WTF::RunLoop::performWork()
                  50 JavaScriptCore: WTF::RunLoop::performWork(void*)
                    50 CoreFoundation: __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
                      50 CoreFoundation: __CFRunLoopDoSources0
                        50 CoreFoundation: __CFRunLoopRun
                          50 CoreFoundation: CFRunLoopRunSpecific
                            50 HIToolbox: RunCurrentEventLoopInMode
                              50 HIToolbox: ReceiveNextEventCommon
                                50 HIToolbox: _BlockUntilNextEventMatchingListInModeWithFilter
                                  50 AppKit: _DPSNextEvent
                                    50 AppKit: -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
                                      50 Safari: -[BrowserApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
                                        50 AppKit: -[NSApplication run]
                                          50 AppKit: NSApplicationMain
                                            50 libdyld.dylib: start</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1215506</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2016-07-28 23:52:00 -0700</bug_when>
    <thetext>7/28/16, 7:25 PM Ryosuke Niwa:
Alexey and I looked into this but we couldn’t figure out where the message is marked as invalid.

We initially thought MESSAGE_CHECK in WebPageProxy::attributedStringForCharacterRangeCallback was failing:
void WebPageProxy::attributedStringForCharacterRangeCallback(const AttributedString&amp; string, const EditingRange&amp; actualRange, uint64_t callbackID)
{
    MESSAGE_CHECK(actualRange.isValid());

EditingRange::isValid checks location + length &gt;= location.  This can fail if location + length overflows or length is negative.  length can’t be negative since it’s uint64_t, and location is guaranteeed to be less than INT_MAX inside rangeFromEditingRange, which returns nullptr if location &gt; INT_MAX.  It’s also quite inconceivable that location + length doesn’t fit in 2^31 since what we’re counting here is the visible number of characters.

Another place where the message can be marked as invalid would be decoding.  But I couldn’t spot any obvious flaws in ArgumentCodersMac.mm that decodes NSAttributedString by either code inspection or reconvering text in Japanese input method.

I did find one case in which we hit the following assertions in WebPage::attributedSubstringForCharacterRangeAsync:

ASSERT([attributedString length] == editingRange.length + 1);
ASSERT([[attributedString string] characterAtIndex:editingRange.length] == &apos;\n&apos; || [[attributedString string] characterAtIndex:editingRange.length] == &apos; &apos;);
result.string = [attributedString attributedSubstringFromRange:NSMakeRange(0, editingRange.length)];

when the attributed string contains an image but this doesn’t result in a crash because of the truncation that happens in the third line before sending the message.

7/28/16, 7:32 PM Ryosuke Niwa:
Overall, there isn’t an obvious bug fix we can do here.

Now, for MESSAGE_CHECK, then we could speculatively adding ASSERT_RELEASE(editingRange.isValid()) in WebContent process side so that it kills WebContent process instead of Safari, which is probably a better UX, and we can dig into the range issue more once we determine this new assertion fails after GM.  Alternatively, we could remove the asssertion in UIProcess side and “fix up” the range but this has a downside that it may simply cover up a bug elsewhere.  This is probably the least risky path forward.

Either of those fixes don’t address the possibility that decoding is failing.  However, given the lack of a reproducible test case and an insight as to where the crash is happening, it’s hard to tell where problem lies in decoding.  One thing we can do is to add more release assertions in the decoding code of NSAttributedString so that we can pinpoint which decoding phase is failing but this will also result in a crash.  We would at least get a crash log with more useful information, however.

7/28/16, 10:26 PM Ryosuke Niwa:
This appears to be top #3 crasher in Gala: https://crashtracer.apple.com/app/show/Safari?train=SUGalaFiesta&amp;users=external

I’ve looked through the logs and most of crash logs contain libSimplifiedChineseConverter.dylib which means this crash is encoutered by mainland Chinese users.

7/28/16, 10:28 PM Ryosuke Niwa:
It looks like a failure in decode won’t cause a crash as handleMessage simply bails out:

template&lt;typename T, typename C, typename MF&gt;
void handleMessage(MessageDecoder&amp; decoder, C* object, MF function)
{
    typename T::DecodeType arguments;
    if (!decoder.decode(arguments)) {
        ASSERT(decoder.isInvalid());
        return;
    }

    callMemberFunction(WTFMove(arguments), object, function);
}

* thread #1: tid = 0x460929, 0x0000000107134a33 WebKit`void IPC::handleMessage&lt;Messages::WebPageProxy::AttributedStringForCharacterRangeCallback, WebKit::WebPageProxy, void (WebKit::WebPageProxy::*)(WebKit::AttributedString const&amp;, WebKit::EditingRange const&amp;, unsigned long long)&gt;(decoder=0x0000000118974000, object=0x00007fff2e000a18, function=0x0000000107117f70)(WebKit::AttributedString const&amp;, WebKit::EditingRange const&amp;, unsigned long long)) + 211 at HandleMessage.h:87, queue = &apos;com.apple.main-thread&apos;, stop reason = step over
  * frame #0: 0x0000000107134a33 WebKit`void IPC::handleMessage&lt;Messages::WebPageProxy::AttributedStringForCharacterRangeCallback, WebKit::WebPageProxy, void (WebKit::WebPageProxy::*)(WebKit::AttributedString const&amp;, WebKit::EditingRange const&amp;, unsigned long long)&gt;(decoder=0x0000000118974000, object=0x00007fff2e000a18, function=0x0000000107117f70)(WebKit::AttributedString const&amp;, WebKit::EditingRange const&amp;, unsigned long long)) + 211 at HandleMessage.h:87
    frame #1: 0x000000010712cfa4 WebKit`WebKit::WebPageProxy::didReceiveMessage(this=0x00007fff2e000a18, connection=0x000000011898f1a0, decoder=0x0000000118974000) + 10820 at WebPageProxyMessageReceiver.cpp:608
    frame #2: 0x0000000106ac8d58 WebKit`IPC::MessageReceiverMap::dispatchMessage(this=0x00000001157e7838, connection=0x000000011898f1a0, decoder=0x0000000118974000) + 456 at MessageReceiverMap.cpp:123
    frame #3: 0x00000001069adca4 WebKit`WebKit::ChildProcessProxy::dispatchMessage(this=0x00000001157e7800, connection=0x000000011898f1a0, decoder=0x0000000118974000) + 52 at ChildProcessProxy.cpp:162
    frame #4: 0x000000010722bafa WebKit`WebKit::WebProcessProxy::didReceiveMessage(this=0x00000001157e7800, connection=0x000000011898f1a0, decoder=0x0000000118974000) + 58 at WebProcessProxy.cpp:497
    frame #5: 0x00000001069be003 WebKit`IPC::Connection::dispatchMessage(this=0x000000011898f1a0, decoder=0x0000000118974000) + 51 at Connection.cpp:917
    frame #6: 0x00000001069b3450 WebKit`IPC::Connection::dispatchMessage(this=0x000000011898f1a0, message=unique_ptr&lt;IPC::MessageDecoder, std::__1::default_delete&lt;IPC::MessageDecoder&gt; &gt; at 0x00007fff5c805d00) + 784 at Connection.cpp:950
    frame #7: 0x00000001069be5f3 WebKit`IPC::Connection::dispatchOneMessage(this=0x000000011898f1a0) + 1507 at Connection.cpp:985
    frame #8: 0x00000001069d355d WebKit`IPC::Connection::enqueueIncomingMessage(this=0x00000001157e5158)::$_10::operator()() + 29 at Connection.cpp:911
    frame #9: 0x00000001069d34b9 WebKit`WTF::Function&lt;void ()&gt;::CallableWrapper&lt;IPC::Connection::enqueueIncomingMessage(this=0x00000001157e5150)::$_10&gt;::call() + 25 at Function.h:101</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1215507</commentid>
    <comment_count>2</comment_count>
      <attachid>284849</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2016-07-28 23:57:56 -0700</bug_when>
    <thetext>Created attachment 284849
Adds a speculative fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1215628</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2016-07-29 11:46:30 -0700</bug_when>
    <thetext>Committed r203909: &lt;http://trac.webkit.org/changeset/203909&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>284849</attachid>
            <date>2016-07-28 23:57:56 -0700</date>
            <delta_ts>2016-07-29 06:31:56 -0700</delta_ts>
            <desc>Adds a speculative fix</desc>
            <filename>bug-160334-20160728235642.patch</filename>
            <type>text/plain</type>
            <size>2544</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJLaXQyL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb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sIGNhbGxiYWNrSUQpKTsKIH0KIAogdm9pZCBXZWJQYWdlOjpm
b250QXRTZWxlY3Rpb24odWludDY0X3QgY2FsbGJhY2tJRCkK
</data>
<flag name="review"
          id="308513"
          type_id="1"
          status="+"
          setter="ap"
    />
          </attachment>
      

    </bug>

</bugzilla>