<?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>276677</bug_id>
          
          <creation_ts>2024-07-16 13:28:50 -0700</creation_ts>
          <short_desc>[REGRESSION] LocalDOMWindow::getMatchedCSSRules asserts when passed null/empty pseudoElement</short_desc>
          <delta_ts>2024-07-19 10:26: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>CSS</component>
          <version>Safari 18</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</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>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jonathan Hammer">jonathan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>koivisto</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2046541</commentid>
    <comment_count>0</comment_count>
    <who name="Jonathan Hammer">jonathan</who>
    <bug_when>2024-07-16 13:28:50 -0700</bug_when>
    <thetext>In debug builds, calling LocalDOMWindow::getMatchedCSSRules with a null or empty pseudoElement parameter results in an assertion failure in PseudoElementRequest(). In release builds, getMatchedCSSRules incorrectly returns null. This API, while deprecated, is still exposed to Obj-C clients via -[DOMDocument getMatchedCSSRules:pseudoElement:authorOnly:], and our macOS application [1] relies on it working correctly. Our app is currently broken on the macOS Sequoia beta builds due to this bug.

It looks like this is the commit that inadvertently caused the issue:

https://github.com/WebKit/WebKit/commit/4d69396f11340703fd2c7cffc87e2ed11b26633f

In that commit, two changes combined to create the bug:

(1) The signature for Resolver::pseudoStyleRulesForElement changed (the pseudoId parameter is now a std::optional&lt;PseudoId&gt; instead of PseudoId)
(2) The PseudoElementRequest constructor was modified to assert pseudoId != PseudoId::None

When LocalDOMWindow::getMatchedCSSRules is called with an empty pseudoElement parameter, it ends up calling pseudoStyleRulesForElement with PseudoId::None, which triggers the assertion. 

Proposed Fix:

The method getMatchedCSSRules should be changed to call pseudoStyleRulesForElement with std::nullopt instead of PseudoId::None.

LocalDOMWindow.cpp:1636:

-    auto pseudoId = pseudoElementIdentifier ? pseudoElementIdentifier-&gt;pseudoId : PseudoId::None;
+    std::optional&lt;PseudoId&gt; pseudoId;
+    if (pseudoElementIdentifier)
+        pseudoId = pseudoElementIdentifier-&gt;pseudoId;

Thanks,
Jonathan

[1]: https://directmailmac.com</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046542</commentid>
    <comment_count>1</comment_count>
      <attachid>471896</attachid>
    <who name="Jonathan Hammer">jonathan</who>
    <bug_when>2024-07-16 13:31:11 -0700</bug_when>
    <thetext>Created attachment 471896
Patch to fix LocalDOMWindow::getMatchedCSSRules</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046727</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Hammer">jonathan</who>
    <bug_when>2024-07-17 07:59:58 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/30906</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2047005</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-07-18 07:44:54 -0700</bug_when>
    <thetext>Committed 281088@main (9b380bdb5e47): &lt;https://commits.webkit.org/281088@main&gt;

Reviewed commits have been landed. Closing PR #30906 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2047006</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-07-18 07:45:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/132009080&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2047213</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-07-19 10:26:30 -0700</bug_when>
    <thetext>Committed 280938.67@integration/ci/132009080_9b380bdb5e_safari-7619-branch (372659bf557d): &lt;https://commits.webkit.org/280938.67@integration/ci/132009080_9b380bdb5e_safari-7619-branch&gt;

Reviewed commits have been landed. Closing PR #1433 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>471896</attachid>
            <date>2024-07-16 13:31:11 -0700</date>
            <delta_ts>2024-07-16 13:31:11 -0700</delta_ts>
            <desc>Patch to fix LocalDOMWindow::getMatchedCSSRules</desc>
            <filename>patch</filename>
            <type>text/plain</type>
            <size>755</size>
            <attacher name="Jonathan Hammer">jonathan</attacher>
            
              <data encoding="base64">LS0tIExvY2FsRE9NV2luZG93Lm9sZC5jcHAJMjAyNC0wNy0xNiAxMzoyOToyNQorKysgTG9jYWxE
T01XaW5kb3cuY3BwCTIwMjQtMDctMTYgMTI6Mzg6MjUKQEAgLTE2MzMsOCArMTYzMywxMCBAQAog
ICAgIGF1dG8gW3BzZXVkb0VsZW1lbnRJc1BhcnNhYmxlLCBwc2V1ZG9FbGVtZW50SWRlbnRpZmll
cl0gPSBDU1NTZWxlY3RvclBhcnNlcjo6cGFyc2VQc2V1ZG9FbGVtZW50KHBzZXVkb0VsZW1lbnQs
IHBhcnNlckNvbnRleHQpOwogICAgIGlmICghKHBzZXVkb0VsZW1lbnRJc1BhcnNhYmxlIHx8IChw
c2V1ZG9FbGVtZW50SWRlbnRpZmllciAmJiAhcHNldWRvRWxlbWVudElkZW50aWZpZXItPm5hbWVB
cmd1bWVudC5pc051bGwoKSkpICYmICFwc2V1ZG9FbGVtZW50LmlzRW1wdHkoKSkKICAgICAgICAg
cmV0dXJuIG51bGxwdHI7Ci0gICAgYXV0byBwc2V1ZG9JZCA9IHBzZXVkb0VsZW1lbnRJZGVudGlm
aWVyID8gcHNldWRvRWxlbWVudElkZW50aWZpZXItPnBzZXVkb0lkIDogUHNldWRvSWQ6Ok5vbmU7
Ci0KKyAgICBzdGQ6Om9wdGlvbmFsPFBzZXVkb0lkPiBwc2V1ZG9JZDsKKyAgICBpZiAocHNldWRv
RWxlbWVudElkZW50aWZpZXIpCisgICAgICAgIHBzZXVkb0lkID0gcHNldWRvRWxlbWVudElkZW50
aWZpZXItPnBzZXVkb0lkOworICAgIAogICAgIFJlZlB0ciBmcmFtZSA9IHRoaXMtPmZyYW1lKCk7
CiAgICAgZnJhbWUtPnByb3RlY3RlZERvY3VtZW50KCktPnN0eWxlU2NvcGUoKS5mbHVzaFBlbmRp
bmdVcGRhdGUoKTsKIAo=
</data>

          </attachment>
      

    </bug>

</bugzilla>