<?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>22168</bug_id>
          
          <creation_ts>2008-11-10 17:26:06 -0800</creation_ts>
          <short_desc>Chromium is seeing crashes using TextIterator</short_desc>
          <delta_ts>2008-12-02 11:07:43 -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>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Eric Seidel (no email)">eric</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>justin.garcia</cc>
    
    <cc>mitz</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>98240</commentid>
    <comment_count>0</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-11-10 17:26:06 -0800</bug_when>
    <thetext>http://code.google.com/p/chromium/issues/detail?id=4122

I&apos;m not sure why the bug is hidden, and I don&apos;t understand chromium&apos;s bug system enough to change it.  So I&apos;m just filing this here.

We&apos;re seeing a crash when using TextIterator, after an advance() call, sometimes the resulting characters() is 0x02, the only way I can see that happening is if emitText is called with a node with a null string.

The only way I see emitText ever being called where the string wasn&apos;t null checked is here:

            // Handle either a single newline character (which becomes a space),
            // or a run of characters that does not include a newline.
            // This effectively translates newlines to spaces without copying the text.
            if (str[runStart] == &apos;\n&apos;) {
                emitCharacter(&apos; &apos;, m_node, 0, runStart, runStart + 1);
                m_offset = runStart + 1;
            } else {
                int subrunEnd = str.find(&apos;\n&apos;, runStart);
                if (subrunEnd == -1 || subrunEnd &gt; runEnd)
                    subrunEnd = runEnd;
    
                m_offset = subrunEnd;
                emitText(m_node, runStart, subrunEnd);
            }

I&apos;m not fully confident in my mental debugging, so I&apos;d like to try and catch this in the wild with more stack information.  Hence, I&apos;m suggesting adding this ASSERT.  There are various ways to fix this, including making it more explicit what strings we&apos;re checking.  In the one call site which might be wrong, we check &quot;str&quot; length before calling emitText, but m_node does not necessarily still have an renderer() which returns that string, since m_node can be changed independently of &quot;str&quot;.

I&apos;ll post a patch with the ASSERT shortly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98241</commentid>
    <comment_count>1</comment_count>
      <attachid>25036</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-11-10 17:31:40 -0800</bug_when>
    <thetext>Created attachment 25036
Add ASSERT to catch crash after advance()

 WebCore/ChangeLog                |   11 +++++++++++
 WebCore/editing/TextIterator.cpp |    3 ++-
 2 files changed, 13 insertions(+), 1 deletions(-)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98246</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Larson (Google)">mal</who>
    <bug_when>2008-11-10 18:23:37 -0800</bug_when>
    <thetext>Chromium bug 4122 contained some private data, so it was closed. The real bug is http://crbug.com/4123.

We&apos;re seeing this crash in automated test runs, but not in user crash reports. It&apos;s possibly a side effect of the test system.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98260</commentid>
    <comment_count>3</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-11-10 21:28:44 -0800</bug_when>
    <thetext>Thank you mark.  I still think WebKit should add this ASSERT, and eventually change our approach here.  (i.e. change the arguments to this function to be less fragile)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98293</commentid>
    <comment_count>4</comment_count>
      <attachid>25036</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-11-11 09:09:39 -0800</bug_when>
    <thetext>Comment on attachment 25036
Add ASSERT to catch crash after advance()

I see no harm in adding this assertion, but little benefit in doing so. The line that initializes m_lastCharacter will crash if str.characters() is 0; this will move that crash up a few lines but not detect any additional failure cases.

The evidence does not match the theory that renderer-&gt;text() is a null string. In TextIterator::handleTextBox we&apos;ve already fetched renderer-&gt;text() and dereferenced it by calling str[runStart] before calling emitText. So there&apos;s no real chance that it&apos;s a null string in that code path.

If characters() is 0x02 that does not indicate a null string. Instead it indicates a StringImpl that has been deallocated or overwritten. characters() is 0 in a null string.

r=me because there&apos;s no harm in adding the assertion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101027</commentid>
    <comment_count>5</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-12-02 11:07:43 -0800</bug_when>
    <thetext>Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	WebCore/ChangeLog
	M	WebCore/editing/TextIterator.cpp
Committed r38908
</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>25036</attachid>
            <date>2008-11-10 17:31:40 -0800</date>
            <delta_ts>2008-11-11 09:09:39 -0800</delta_ts>
            <desc>Add ASSERT to catch crash after advance()</desc>
            <filename>Add-ASSERT-to-catch-crash-after-advance-.patch</filename>
            <type>text/plain</type>
            <size>1365</size>
            <attacher name="Eric Seidel (no email)">eric</attacher>
            
              <data encoding="base64">MTA3MDAyZGZlZWVkOWFhNzA1NGJiZGYwYmM4Njk1Mjg3ZTAxYTA4NApkaWZmIC0tZ2l0IGEvV2Vi
Q29yZS9DaGFuZ2VMb2cgYi9XZWJDb3JlL0NoYW5nZUxvZwppbmRleCA5OTllYzM2Li4yMDJmYzFi
IDEwMDY0NAotLS0gYS9XZWJDb3JlL0NoYW5nZUxvZworKys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ZSwKICAgICBtX2xhc3RDaGFyYWN0
ZXIgPSBjOwogfQogCi12b2lkIFRleHRJdGVyYXRvcjo6ZW1pdFRleHQoTm9kZSAqdGV4dE5vZGUs
IGludCB0ZXh0U3RhcnRPZmZzZXQsIGludCB0ZXh0RW5kT2Zmc2V0KQordm9pZCBUZXh0SXRlcmF0
b3I6OmVtaXRUZXh0KE5vZGUqIHRleHROb2RlLCBpbnQgdGV4dFN0YXJ0T2Zmc2V0LCBpbnQgdGV4
dEVuZE9mZnNldCkKIHsKICAgICBSZW5kZXJUZXh0KiByZW5kZXJlciA9IHN0YXRpY19jYXN0PFJl
bmRlclRleHQqPihtX25vZGUtPnJlbmRlcmVyKCkpOwogICAgIFN0cmluZyBzdHIgPSByZW5kZXJl
ci0+dGV4dCgpOworICAgIEFTU0VSVChzdHIuY2hhcmFjdGVycygpKTsKIAogICAgIG1fcG9zaXRp
b25Ob2RlID0gdGV4dE5vZGU7CiAgICAgbV9wb3NpdGlvbk9mZnNldEJhc2VOb2RlID0gMDsK
</data>
<flag name="review"
          id="11499"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>