LibWeb: Limit HTMLMarqueeElement attributes to allowed values

If `HTMLMarqueeElemnt.scrollAmount` or `HTMLMarqueeElemnt.scrollDelay`
is set to a value larger than 2147483647, then it should be set to its
default value.
This commit is contained in:
Tim Ledbetter 2024-11-26 20:40:48 +00:00 committed by Andreas Kling
parent e5c99b475a
commit a8719a706b
Notes: github-actions[bot] 2024-11-27 10:03:59 +00:00
3 changed files with 40 additions and 2 deletions

View file

@ -67,7 +67,7 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_amount()
{
// The scrollAmount IDL attribute must reflect the scrollamount content attribute. The default value is 6.
if (auto scroll_amount_string = get_attribute(HTML::AttributeNames::scrollamount); scroll_amount_string.has_value()) {
if (auto scroll_amount = parse_non_negative_integer(*scroll_amount_string); scroll_amount.has_value())
if (auto scroll_amount = parse_non_negative_integer(*scroll_amount_string); scroll_amount.has_value() && *scroll_amount <= 2147483647)
return *scroll_amount;
}
return 6;
@ -76,6 +76,8 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_amount()
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrollamount
WebIDL::ExceptionOr<void> HTMLMarqueeElement::set_scroll_amount(WebIDL::UnsignedLong value)
{
if (value > 2147483647)
value = 6;
return set_attribute(HTML::AttributeNames::scrollamount, String::number(value));
}
@ -84,7 +86,7 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_delay()
{
// The scrollDelay IDL attribute must reflect the scrolldelay content attribute. The default value is 85.
if (auto scroll_delay_string = get_attribute(HTML::AttributeNames::scrolldelay); scroll_delay_string.has_value()) {
if (auto scroll_delay = parse_non_negative_integer(*scroll_delay_string); scroll_delay.has_value())
if (auto scroll_delay = parse_non_negative_integer(*scroll_delay_string); scroll_delay.has_value() && *scroll_delay <= 2147483647)
return *scroll_delay;
}
return 85;
@ -93,6 +95,8 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_delay()
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrolldelay
WebIDL::ExceptionOr<void> HTMLMarqueeElement::set_scroll_delay(WebIDL::UnsignedLong value)
{
if (value > 2147483647)
value = 85;
return set_attribute(HTML::AttributeNames::scrolldelay, String::number(value));
}

View file

@ -14,3 +14,35 @@ img.getAttribute("hspace") after img.setAttribute("hspace", "4294967295"): 42949
img.hspace after img.setAttribute("hspace", "4294967295"): 0
img.getAttribute("hspace") after img.hspace = 4294967295: 0
img.hspace after img.hspace = 4294967295: 0
marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "1"): 1
marquee.scrollAmount after marquee.setAttribute("scrollamount", "1"): 1
marquee.getAttribute("scrollamount") after marquee.scrollAmount = 1: 1
marquee.scrollAmount after marquee.scrollAmount = 1: 1
marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "2147483647"): 2147483647
marquee.scrollAmount after marquee.setAttribute("scrollamount", "2147483647"): 2147483647
marquee.getAttribute("scrollamount") after marquee.scrollAmount = 2147483647: 2147483647
marquee.scrollAmount after marquee.scrollAmount = 2147483647: 2147483647
marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "2147483648"): 2147483648
marquee.scrollAmount after marquee.setAttribute("scrollamount", "2147483648"): 6
marquee.getAttribute("scrollamount") after marquee.scrollAmount = 2147483648: 6
marquee.scrollAmount after marquee.scrollAmount = 2147483648: 6
marquee.getAttribute("scrollamount") after marquee.setAttribute("scrollAmount", "4294967295"): 4294967295
marquee.scrollAmount after marquee.setAttribute("scrollamount", "4294967295"): 6
marquee.getAttribute("scrollamount") after marquee.scrollAmount = 4294967295: 6
marquee.scrollAmount after marquee.scrollAmount = 4294967295: 6
marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "1"): 1
marquee.scrollDelay after marquee.setAttribute("scrolldelay", "1"): 1
marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 1: 1
marquee.scrollDelay after marquee.scrollDelay = 1: 1
marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "2147483647"): 2147483647
marquee.scrollDelay after marquee.setAttribute("scrolldelay", "2147483647"): 2147483647
marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 2147483647: 2147483647
marquee.scrollDelay after marquee.scrollDelay = 2147483647: 2147483647
marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "2147483648"): 2147483648
marquee.scrollDelay after marquee.setAttribute("scrolldelay", "2147483648"): 85
marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 2147483648: 85
marquee.scrollDelay after marquee.scrollDelay = 2147483648: 85
marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "4294967295"): 4294967295
marquee.scrollDelay after marquee.setAttribute("scrolldelay", "4294967295"): 85
marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 4294967295: 85
marquee.scrollDelay after marquee.scrollDelay = 4294967295: 85

View file

@ -23,5 +23,7 @@
}
testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = value);
testProperty("marquee", "scrollAmount", (marquee) => marquee.scrollAmount, (marquee, value) => marquee.scrollAmount = value);
testProperty("marquee", "scrollDelay", (marquee) => marquee.scrollDelay, (marquee, value) => marquee.scrollDelay = value);
});
</script>