<?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>18859</bug_id>
          
          <creation_ts>2008-05-02 17:19:55 -0700</creation_ts>
          <short_desc>SVGRootInlineBox::buildTextChunks can do an invalid downcast</short_desc>
          <delta_ts>2008-05-06 10:38:40 -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>SVG</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</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="Jonathan Haas">myrdred</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79509</commentid>
    <comment_count>0</comment_count>
    <who name="Jonathan Haas">myrdred</who>
    <bug_when>2008-05-02 17:19:55 -0700</bug_when>
    <thetext>rendering/SVGRootInlineBox.cpp:1382:

            Node* node = text-&gt;element()-&gt;parent();
            if (node &amp;&amp; node-&gt;isSVGElement())
                textContent = static_cast&lt;SVGTextContentElement*&gt;(node);
            ASSERT(textContent);

The problem is that the parent of the element node may not be an SVGTextContentElement. For example, in this SVG:

&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
  &lt;text&gt;
    &lt;a&gt;Oh snap!&lt;/a&gt;
  &lt;/text&gt;
&lt;/svg&gt;

...the parent node is an SVGAElement, which doesn&apos;t inherit SVGTextContentElement. To see this more clearly, replace the code above with:

            Node* node = text-&gt;element()-&gt;parent();
            if (node &amp;&amp; node-&gt;isSVGElement()) {
                ASSERT(static_cast&lt;SVGElement*&gt;(node)-&gt;isTextContent());
                textContent = static_cast&lt;SVGTextContentElement*&gt;(node);
            }
            ASSERT(textContent);

Build, run Safari, load above SVG, earth-shattering kaboom.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79512</commentid>
    <comment_count>1</comment_count>
      <attachid>20937</attachid>
    <who name="Jonathan Haas">myrdred</who>
    <bug_when>2008-05-02 17:22:42 -0700</bug_when>
    <thetext>Created attachment 20937
patch

proposed patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79591</commentid>
    <comment_count>2</comment_count>
      <attachid>20937</attachid>
    <who name="Rob Buis">rwlbuis</who>
    <bug_when>2008-05-03 13:39:01 -0700</bug_when>
    <thetext>Comment on attachment 20937
patch

The general idea seems good to me. The braces in the if/else are not needed since the blocks 
are both single line.

Please include a testcase in the patch that would crash in the old situation and work
fine with the patch.

r- because of the missing testcase.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79676</commentid>
    <comment_count>3</comment_count>
      <attachid>20969</attachid>
    <who name="Jonathan Haas">myrdred</who>
    <bug_when>2008-05-05 09:20:45 -0700</bug_when>
    <thetext>Created attachment 20969
improved patch

Removed extraneous braces. I assume the braces around the body of the while loop can stay?

There is no good test case for the original, unpatched code. The behavior of an invalid downcast is undefined and implementation-dependent. In the case of MSVC 8, the return value from a call to textContent-&gt;textLength() on the invalid pointer ends up pointing to the m_systemLanguage of SVGAElement::SVGTests. This usually produces innocuous if bogus values. I suppose I might be able to contrive a case where it forced an assert to trigger, but again, the behavior is undefined and there&apos;s no guarantee that the same behavior would result in an Xcode compilatior, or a gcc compilation, or even a different version of MSVC.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79723</commentid>
    <comment_count>4</comment_count>
      <attachid>20969</attachid>
    <who name="Rob Buis">rwlbuis</who>
    <bug_when>2008-05-06 00:23:55 -0700</bug_when>
    <thetext>Comment on attachment 20969
improved patch

Assuming you ran the tests
and no new regressions/crashes occur, r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79760</commentid>
    <comment_count>5</comment_count>
    <who name="Rob Buis">rwlbuis</who>
    <bug_when>2008-05-06 10:38:40 -0700</bug_when>
    <thetext>Landed in r32907.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>20937</attachid>
            <date>2008-05-02 17:22:42 -0700</date>
            <delta_ts>2008-05-05 09:11:22 -0700</delta_ts>
            <desc>patch</desc>
            <filename>patch</filename>
            <type>text/plain</type>
            <size>1571</size>
            <attacher name="Jonathan Haas">myrdred</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiAzMjgyOCkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTQgQEAKKzIwMDgtMDUtMDIgIEpvbmF0aGFuIEhhYXMgIDxteXJkcmVkQGdtYWls
LmNvbT4KKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBo
dHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTg4NTlcCisgICAgICAgIFBy
ZXZlbnRlZCBTVkdSb290SW5saW5lQm94IGZyb20gc3RhdGljX2Nhc3RpbmcgYQorICAgICAgICBu
b2RlIHRvIGEgY2xhc3MgaXQgZG9lc24ndCBpbmhlcml0CisgICAgICAgIAorICAgICAgICAqIHJl
bmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcDoKKyAgICAgICAgKFdlYkNvcmU6OlNWR1Jvb3RJ
bmxpbmVCb3g6OmJ1aWxkVGV4dENodW5rcyk6CisKIDIwMDgtMDUtMDIgIEJlbmphbWluIE90dGUg
IDxvdHRlQGdub21lLm9yZz4KIAogICAgICAgICBSZXZpZXdlZCBieSBBbHAgVG9rZXIuCkluZGV4
OiBXZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAo9PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBX
ZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAkocmV2aXNpb24gMzI4MjEpCisr
KyBXZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAkod29ya2luZyBjb3B5KQpA
QCAtMTM4MCw4ICsxMzgwLDEzIEBAIHZvaWQgU1ZHUm9vdElubGluZUJveDo6YnVpbGRUZXh0Q2h1
bmtzKFYKIAogICAgICAgICAgICAgU1ZHVGV4dENvbnRlbnRFbGVtZW50KiB0ZXh0Q29udGVudCA9
IDA7CiAgICAgICAgICAgICBOb2RlKiBub2RlID0gdGV4dC0+ZWxlbWVudCgpLT5wYXJlbnQoKTsK
LSAgICAgICAgICAgIGlmIChub2RlICYmIG5vZGUtPmlzU1ZHRWxlbWVudCgpKQotICAgICAgICAg
ICAgICAgIHRleHRDb250ZW50ID0gc3RhdGljX2Nhc3Q8U1ZHVGV4dENvbnRlbnRFbGVtZW50Kj4o
bm9kZSk7CisgICAgICAgICAgICB3aGlsZSAobm9kZSAmJiBub2RlLT5pc1NWR0VsZW1lbnQoKSAm
JiAhdGV4dENvbnRlbnQpIHsKKyAgICAgICAgICAgICAgICBpZiAoc3RhdGljX2Nhc3Q8U1ZHRWxl
bWVudCo+KG5vZGUpLT5pc1RleHRDb250ZW50KCkpIHsKKyAgICAgICAgICAgICAgICAgICAgdGV4
dENvbnRlbnQgPSBzdGF0aWNfY2FzdDxTVkdUZXh0Q29udGVudEVsZW1lbnQqPihub2RlKTsKKyAg
ICAgICAgICAgICAgICB9IGVsc2UgeworICAgICAgICAgICAgICAgICAgICBub2RlID0gbm9kZS0+
cGFyZW50Tm9kZSgpOworICAgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgIH0KICAgICAgICAg
ICAgIEFTU0VSVCh0ZXh0Q29udGVudCk7CiAKICAgICAgICAgICAgIC8vIFN0YXJ0IG5ldyBjaGFy
YWN0ZXIgcmFuZ2UgZm9yIHRoZSBmaXJzdCBjaHVuawo=
</data>
<flag name="review"
          id="9159"
          type_id="1"
          status="-"
          setter="rwlbuis"
    />
          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>20969</attachid>
            <date>2008-05-05 09:20:45 -0700</date>
            <delta_ts>2008-05-06 00:23:55 -0700</delta_ts>
            <desc>improved patch</desc>
            <filename>patch</filename>
            <type>text/plain</type>
            <size>1546</size>
            <attacher name="Jonathan Haas">myrdred</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiAzMjgyOCkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTQgQEAKKzIwMDgtMDUtMDIgIEpvbmF0aGFuIEhhYXMgIDxteXJkcmVkQGdtYWls
LmNvbT4KKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBo
dHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTg4NTlcCisgICAgICAgIFBy
ZXZlbnRlZCBTVkdSb290SW5saW5lQm94IGZyb20gc3RhdGljX2Nhc3RpbmcgYQorICAgICAgICBu
b2RlIHRvIGEgY2xhc3MgaXQgZG9lc24ndCBpbmhlcml0CisgICAgICAgIAorICAgICAgICAqIHJl
bmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcDoKKyAgICAgICAgKFdlYkNvcmU6OlNWR1Jvb3RJ
bmxpbmVCb3g6OmJ1aWxkVGV4dENodW5rcyk6CisKIDIwMDgtMDUtMDIgIEJlbmphbWluIE90dGUg
IDxvdHRlQGdub21lLm9yZz4KIAogICAgICAgICBSZXZpZXdlZCBieSBBbHAgVG9rZXIuCkluZGV4
OiBXZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAo9PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBX
ZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAkocmV2aXNpb24gMzI4MjEpCisr
KyBXZWJDb3JlL3JlbmRlcmluZy9TVkdSb290SW5saW5lQm94LmNwcAkod29ya2luZyBjb3B5KQpA
QCAtMTM4MCw4ICsxMzgwLDEyIEBAIHZvaWQgU1ZHUm9vdElubGluZUJveDo6YnVpbGRUZXh0Q2h1
bmtzKFYKIAogICAgICAgICAgICAgU1ZHVGV4dENvbnRlbnRFbGVtZW50KiB0ZXh0Q29udGVudCA9
IDA7CiAgICAgICAgICAgICBOb2RlKiBub2RlID0gdGV4dC0+ZWxlbWVudCgpLT5wYXJlbnQoKTsK
LSAgICAgICAgICAgIGlmIChub2RlICYmIG5vZGUtPmlzU1ZHRWxlbWVudCgpKQotICAgICAgICAg
ICAgICAgIHRleHRDb250ZW50ID0gc3RhdGljX2Nhc3Q8U1ZHVGV4dENvbnRlbnRFbGVtZW50Kj4o
bm9kZSk7CisgICAgICAgICAgICB3aGlsZSAobm9kZSAmJiBub2RlLT5pc1NWR0VsZW1lbnQoKSAm
JiAhdGV4dENvbnRlbnQpIHsKKyAgICAgICAgICAgICAgICBpZiAoc3RhdGljX2Nhc3Q8U1ZHRWxl
bWVudCo+KG5vZGUpLT5pc1RleHRDb250ZW50KCkpCisgICAgICAgICAgICAgICAgICAgIHRleHRD
b250ZW50ID0gc3RhdGljX2Nhc3Q8U1ZHVGV4dENvbnRlbnRFbGVtZW50Kj4obm9kZSk7CisgICAg
ICAgICAgICAgICAgZWxzZQorICAgICAgICAgICAgICAgICAgICBub2RlID0gbm9kZS0+cGFyZW50
Tm9kZSgpOworICAgICAgICAgICAgfQogICAgICAgICAgICAgQVNTRVJUKHRleHRDb250ZW50KTsK
IAogICAgICAgICAgICAgLy8gU3RhcnQgbmV3IGNoYXJhY3RlciByYW5nZSBmb3IgdGhlIGZpcnN0
IGNodW5rCg==
</data>
<flag name="review"
          id="9171"
          type_id="1"
          status="+"
          setter="rwlbuis"
    />
          </attachment>
      

    </bug>

</bugzilla>