<?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>31353</bug_id>
          
          <creation_ts>2009-11-11 08:30:48 -0800</creation_ts>
          <short_desc>WebCore::Media::matchMedium NULL pointer crash</short_desc>
          <delta_ts>2010-09-29 08:26:50 -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>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows Vista</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>33913</dup_id>
          
          <bug_file_loc>http://skypher.com/SkyLined/Repro/WebKit/Bug%2031353%20-%20WebCore..Media..matchMedium%20NULL%20pointer/repro.html</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Berend-Jan Wever">skylined</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>eric.carlson</cc>
    
    <cc>eric</cc>
    
    <cc>paulirish</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>yael</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>162483</commentid>
    <comment_count>0</comment_count>
      <attachid>42963</attachid>
    <who name="Berend-Jan Wever">skylined</who>
    <bug_when>2009-11-11 08:30:48 -0800</bug_when>
    <thetext>Created attachment 42963
Repro case

The below HTML causes a NULL pointer in &quot;WebCore::Media::matchMedium&quot; (WebKit/WebCore/css/Media.cpp):

&lt;IFRAME id=&quot;w&quot; src=&quot;http://www.google.com&quot;&gt;&lt;/IFRAME&gt;
&lt;SCRIPT&gt;
  // Get a reference to a window (window.open can also be used instead of an IFRAME)
  w=document.getElementById(&quot;w&quot;).contentWindow;
  // Get a reference to the media object
  m=w.media;
  // Navigate the window
  w.location.reload();
  // Wait for the window to navigate and crash
  setTimeout(function () { m.matchMedium(); }, 1000);
&lt;/SCRIPT&gt;

Looking at the code, I think that the root cause is that the function relies on m_window to have a document, which it may not have:

bool Media::matchMedium(const String&amp; query) const
{
    Document* document = m_window-&gt;document(); // *** what if this is NULL?
    Frame* frame = m_window-&gt;frame();

    CSSStyleSelector* styleSelector = document-&gt;styleSelector();
    Element* docElement = document-&gt;documentElement();
    if (!styleSelector || !docElement || !frame)
        return false;

    RefPtr&lt;RenderStyle&gt; rootStyle = styleSelector-&gt;styleForElement(docElement, 0 /*defaultParent*/, false /*allowSharing*/, true /*resolveForRootDefault*/);
    RefPtr&lt;MediaList&gt; media = MediaList::create();

    ExceptionCode ec = 0;
    media-&gt;setMediaText(query, ec);
    if (ec)
        return false;

    MediaQueryEvaluator screenEval(type(), frame, rootStyle.get());
    return screenEval.eval(media.get());
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>162484</commentid>
    <comment_count>1</comment_count>
    <who name="Berend-Jan Wever">skylined</who>
    <bug_when>2009-11-11 08:32:41 -0800</bug_when>
    <thetext>Added online repro link</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>162485</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-11-11 08:33:40 -0800</bug_when>
    <thetext>Thank you for the bug.  CCing one of our media folks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>162488</commentid>
    <comment_count>3</comment_count>
    <who name="Berend-Jan Wever">skylined</who>
    <bug_when>2009-11-11 08:35:08 -0800</bug_when>
    <thetext>Chrome tracking bug: http://code.google.com/p/chromium/issues/detail?id=27386</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>162490</commentid>
    <comment_count>4</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2009-11-11 08:35:54 -0800</bug_when>
    <thetext>Actually, different kind of &quot;media&quot; than I initially thought.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>286828</commentid>
    <comment_count>5</comment_count>
    <who name="Berend-Jan Wever">skylined</who>
    <bug_when>2010-09-29 06:42:59 -0700</bug_when>
    <thetext>This no longer reproduces in latest Chromium - I assume it has been fixed at some point. My fuzzers should find it again if it is not fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>286893</commentid>
    <comment_count>6</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-09-29 08:26:50 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 33913 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>42963</attachid>
            <date>2009-11-11 08:30:48 -0800</date>
            <delta_ts>2009-11-11 08:30:48 -0800</delta_ts>
            <desc>Repro case</desc>
            <filename>repro.html</filename>
            <type>text/html</type>
            <size>417</size>
            <attacher name="Berend-Jan Wever">skylined</attacher>
            
              <data encoding="base64">PElGUkFNRSBpZD0idyIgc3JjPSJodHRwOi8vd3d3Lmdvb2dsZS5jb20iPjwvSUZSQU1FPg0KPFND
UklQVD4NCiAgLy8gR2V0IGEgcmVmZXJlbmNlIHRvIGEgd2luZG93ICh3aW5kb3cub3BlbiBjYW4g
YWxzbyBiZSB1c2VkIGluc3RlYWQgb2YgYW4gSUZSQU1FKQ0KICB3PWRvY3VtZW50LmdldEVsZW1l
bnRCeUlkKCJ3IikuY29udGVudFdpbmRvdzsNCiAgLy8gR2V0IGEgcmVmZXJlbmNlIHRvIHRoZSBt
ZWRpYSBvYmplY3QNCiAgbT13Lm1lZGlhOw0KICAvLyBOYXZpZ2F0ZSB0aGUgd2luZG93DQogIHcu
bG9jYXRpb24ucmVsb2FkKCk7DQogIC8vIFdhaXQgZm9yIHRoZSB3aW5kb3cgdG8gbmF2aWdhdGUg
YW5kIGNyYXNoDQogIHNldFRpbWVvdXQoZnVuY3Rpb24gKCkgeyBtLm1hdGNoTWVkaXVtKCk7IH0s
IDEwMDApOw0KPC9TQ1JJUFQ+
</data>

          </attachment>
      

    </bug>

</bugzilla>