Skip to content

dom: Avoid crashing on empty favicon href attribute#41056

Merged
mrobinson merged 1 commit intoservo:mainfrom
webbeef:empty-favicon-href
Dec 6, 2025
Merged

dom: Avoid crashing on empty favicon href attribute#41056
mrobinson merged 1 commit intoservo:mainfrom
webbeef:empty-favicon-href

Conversation

@webbeef
Copy link
Copy Markdown
Contributor

@webbeef webbeef commented Dec 4, 2025

Add a check to handle_favicon_url() similar to the ones done in similar functions: handle_stylesheet_url() and fetch_and_process_prefetch_link()

Testing: Check that loading http://chiptune.com/ doesn't crash anymore.
Fixes: #41047

@webbeef webbeef requested a review from gterzian as a code owner December 4, 2025 18:07
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 4, 2025
Comment on lines 631 to 633
let Ok(href) = self.Href().parse() else {
return;
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this return here catch an empty string? Or does the empty string somehow parse to a valid url?

And if it doesn't, please use href instead of self.Href() here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.Href() does the extra work of resolving to an absolute URL, so when href is empty it returns the document url and parses successfully. So I think this part should not change, since we want the absolute url that self.Href() produces.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

Can you add a regression test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a crash test in tests/wpt/mozilla/tests/mozilla/link_empty_href_crash.html . Not sure if this is the right location!

@jdm jdm added the S-needs-tests New tests have been requested by a reviewer. label Dec 4, 2025
@webbeef webbeef force-pushed the empty-favicon-href branch 2 times, most recently from ed9eada to 505bd07 Compare December 5, 2025 08:22
Comment on lines +1 to +13
<!doctype html>
<meta charset="utf-8">
<title>Test for #41047: Panic when the href attribute of a link is empty.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
var link = document.createElement("link");
link.setAttribute("rel", "icon");
link.setAttribute("href", "");
document.head.appendChild(link);
}, "Doesn't crash when setting an empty href link");
</script>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this test could be upstreamed into the WPT repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - is that fine to move it under tests/wpt/tests/dom/link_empty_href_crash.html instead?

Copy link
Copy Markdown
Contributor

@simonwuelker simonwuelker Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<link> elements are a HTML concept, so html is the better directory for WPT. How about tests/wpt/tests/html/links/icon/empty-href-crash.html. I think the filename has to end with -crash to make the harness recognize it as a crashtest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in latest commit

@servo-wpt-sync
Copy link
Copy Markdown
Collaborator

🤖 Opened new upstream WPT pull request (web-platform-tests/wpt#56521) with upstreamable changes.

Add a check to handle_favicon_url() similar to the ones done in similar
functions: handle_stylesheet_url() and fetch_and_process_prefetch_link()

Signed-off-by: webbeef <[email protected]>
@webbeef webbeef force-pushed the empty-favicon-href branch from 1ec1010 to 74b7309 Compare December 5, 2025 11:23
@servo-wpt-sync
Copy link
Copy Markdown
Collaborator

📝 Transplanted new upstreamable changes to existing upstream WPT pull request (web-platform-tests/wpt#56521).

@webbeef webbeef removed the S-needs-tests New tests have been requested by a reviewer. label Dec 5, 2025
@mrobinson mrobinson changed the title dom: don't crash on empty favicon href attributes. dom: Avoid crashing on empty favicon href attribute Dec 6, 2025
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Dec 6, 2025
@mrobinson mrobinson added this pull request to the merge queue Dec 6, 2025
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 6, 2025
@servo-wpt-sync
Copy link
Copy Markdown
Collaborator

✍ Updated existing upstream WPT pull request (web-platform-tests/wpt#56521) title and body.

Merged via the queue into servo:main with commit c217cbb Dec 6, 2025
30 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

6 participants