<?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>156809</bug_id>
          
          <creation_ts>2016-04-20 14:35:56 -0700</creation_ts>
          <short_desc>Crash under WebCore::TextIterator::subrange()</short_desc>
          <delta_ts>2016-04-20 22:02:09 -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>HTML Editing</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="Chris Dumez">cdumez</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>enrica</cc>
    
    <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1185544</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2016-04-20 14:35:56 -0700</bug_when>
    <thetext>Crash unde WebCore::TextIterator::subrange():
Thread[0] EXC_BAD_ACCESS (SIGSEGV) (KERN_INVALID_ADDRESS at 0x0000000000000008)
[  0] 0x00007fff9969a57e WebCore`WebCore::TextIterator::subrange(WebCore::Range*, int, int) [inlined] WTF::Ref&lt;WebCore::Document&gt;::get() const at Ref.h:60

     0x00007fff9969a56c:     movq %rbx, %rdi
     0x00007fff9969a56f:    callq 0x1b06d0             ; WebCore::TextIterator::advance at TextIterator.cpp:377
     0x00007fff9969a574:     cmpq $0x0, -0xc8(%rbp)
     0x00007fff9969a57c:      jne 0x2ab560             ; &lt;+96&gt; [inlined] WebCore::CharacterIterator::CharacterIterator(WebCore::Range const&amp;, unsigned short) + 55 at TextIterator.cpp:1399
 -&gt;  0x00007fff9969a57e:     movq 0x8(%r13), %rsi
     0x00007fff9969a582:     leaq -0x128(%rbp), %rbx
     0x00007fff9969a589:     movq %r12, %rdi
     0x00007fff9969a58c:     movq %rbx, %rdx
     0x00007fff9969a58f:     movl %r15d, %ecx

[  0] 0x00007fff9969a57e WebCore`WebCore::TextIterator::subrange(WebCore::Range*, int, int) [inlined] WebCore::Range::ownerDocument() const at Range.h:62
       58  	    static PassRefPtr&lt;Range&gt; create(ScriptExecutionContext&amp;);
       59  	    static PassRefPtr&lt;Range&gt; create(Document&amp;, const VisiblePosition&amp;, const VisiblePosition&amp;);
       60  	    ~Range();
       61  	
    -&gt; 62  	    Document&amp; ownerDocument() const { return const_cast&lt;Document&amp;&gt;(m_ownerDocument.get()); }
       63  	
       64  	    Node* startContainer() const { return m_start.container(); }
       65  	    int startOffset() const { return m_start.offset(); }
       66  	    Node* endContainer() const { return m_end.container(); }
    
[  0] 0x00007fff9969a57e WebCore`WebCore::TextIterator::subrange(WebCore::Range*, int, int) + 126 at TextIterator.cpp:2388
       2384	
       2385	PassRefPtr&lt;Range&gt; TextIterator::subrange(Range* entireRange, int characterOffset, int characterCount)
       2386	{
       2387	    CharacterIterator entireRangeIterator(*entireRange);
    -&gt; 2388	    return characterSubrange(entireRange-&gt;ownerDocument(), entireRangeIterator, characterOffset, characterCount);
       2389	}
       2390	
       2391	static inline bool isInsideReplacedElement(TextIterator&amp; iterator)
       2392	{
    
[  1] 0x00007fff9978ac5f WebCore`WebCore::AlternativeTextController::applyAlternativeTextToRange(WebCore::Range const*, WTF::String const&amp;, WebCore::AlternativeTextType, WTF::Vector&lt;WebCore::DocumentMarker::MarkerType, 0ul, WTF::CrashOnOverflow&gt; const&amp;) + 1647 at AlternativeTextController.cpp:281
       277 	    // Recalculate pragraphRangeContainingCorrection, since SpellingCorrectionCommand modified the DOM, such that the original paragraphRangeContainingCorrection is no longer valid. Radar: 10305315 Bugzilla: 89526
       278 	    paragraphRangeContainingCorrection = TextIterator::rangeFromLocationAndLength(&amp;rootNode, paragraphStartIndex, correctionStartOffsetInParagraph + alternative.length());
       279 	    
       280 	    setEnd(paragraphRangeContainingCorrection.get(), m_frame.selection().selection().start());
    -&gt; 281 	    RefPtr&lt;Range&gt; replacementRange = TextIterator::subrange(paragraphRangeContainingCorrection.get(), correctionStartOffsetInParagraph, alternative.length());
       282 	    String newText = plainText(replacementRange.get());
       283 	
       284 	    // Check to see if replacement succeeded.
       285 	    if (newText != alternative)
    
[  2] 0x00007fff9968af38 WebCore`WebCore::AlternativeTextController::handleAlternativeTextUIResult(WTF::String const&amp;) + 632 at AlternativeTextController.cpp:420
[  3] 0x00007fff911aa9d7 WebKitLegacy`-[WebView(WebViewInternal) handleAcceptedAlternativeText:] + 71 at WebView.mm:8542</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185545</commentid>
    <comment_count>1</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2016-04-20 14:36:20 -0700</bug_when>
    <thetext>rdar://problem/21102730</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185547</commentid>
    <comment_count>2</comment_count>
      <attachid>276854</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2016-04-20 14:38:55 -0700</bug_when>
    <thetext>Created attachment 276854
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185679</commentid>
    <comment_count>3</comment_count>
      <attachid>276854</attachid>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2016-04-20 21:08:00 -0700</bug_when>
    <thetext>Comment on attachment 276854
Patch

paragraphRangeContainingCorrection is dereferenced before this.  If this is to avoid null pointer dereferencing in this function, I think this is in the wrong place.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185684</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2016-04-20 21:36:10 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; Comment on attachment 276854 [details]
&gt; Patch
&gt; 
&gt; paragraphRangeContainingCorrection is dereferenced before this.  If this is
&gt; to avoid null pointer dereferencing in this function, I think this is in the
&gt; wrong place.

But before this, it is initialized like so:
paragraphRangeContainingCorrection = range-&gt;cloneRange();

And range-&gt;cloneRange() cannot return null.

This is therefore the right place to null check.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185686</commentid>
    <comment_count>5</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2016-04-20 21:39:00 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; Comment on attachment 276854 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; paragraphRangeContainingCorrection is dereferenced before this.  If this is
&gt; &gt; to avoid null pointer dereferencing in this function, I think this is in the
&gt; &gt; wrong place.
&gt; 
&gt; But before this, it is initialized like so:
&gt; paragraphRangeContainingCorrection = range-&gt;cloneRange();
&gt; 
&gt; And range-&gt;cloneRange() cannot return null.
&gt; 
&gt; This is therefore the right place to null check.

As explained in the Changelog, the issue is only with TextIterator::rangeFromLocationAndLength() potentially returning null.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185695</commentid>
    <comment_count>6</comment_count>
      <attachid>276854</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2016-04-20 22:02:04 -0700</bug_when>
    <thetext>Comment on attachment 276854
Patch

Clearing flags on attachment: 276854

Committed r199807: &lt;http://trac.webkit.org/changeset/199807&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1185696</commentid>
    <comment_count>7</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2016-04-20 22:02:09 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>276854</attachid>
            <date>2016-04-20 14:38:55 -0700</date>
            <delta_ts>2016-04-20 22:02:04 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-156809-20160420143916.patch</filename>
            <type>text/plain</type>
            <size>2224</size>
            <attacher name="Chris Dumez">cdumez</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTk5Nzc4CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggYTRmNWM3MTZlOGFiM2E5
ZTNkMzAzZTc4NDJkZmMwODQyZGQ2MjcwZC4uODk0MzcyMGQ3Mjk0NzA1MTgwYTI1YTdjMTRmYzM0
YWUxZTc3N2YyNyAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDIwIEBACisyMDE2LTA0LTIwICBDaHJp
cyBEdW1leiAgPGNkdW1lekBhcHBsZS5jb20+CisKKyAgICAgICAgQ3Jhc2ggdW5kZXIgV2ViQ29y
ZTo6VGV4dEl0ZXJhdG9yOjpzdWJyYW5nZSgpCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQu
b3JnL3Nob3dfYnVnLmNnaT9pZD0xNTY4MDkKKyAgICAgICAgPHJkYXI6Ly9wcm9ibGVtLzIxMTAy
NzMwPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAgIFRl
eHRJdGVyYXRvcjo6cmFuZ2VGcm9tTG9jYXRpb25BbmRMZW5ndGgoKSBtYXkgcmV0dXJuIG51bGwu
IEh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