LibURL: Fail parsing IPV4 URLs starting with 0x that overflow

Parsing last as an IPV4 number was not returning true in "ends with a
number" as the parsing of that part was overflowing. This means that the
URL is not considered to be an IPv4 address, and is treated as a valid
domain.

Helpfully, the spec also points out in a note that this step is
equivalent to simply checking that the last part ends with 0x followed
by only hex digits - which doesn't suffer from any overflow problem!

Arguably this is an editorial issue in the spec where this should be
clarified a little bit. But for now, fixing this fixes 3 sub tests in
WPT for:

https://wpt.live/url/url-constructor.any.html
This commit is contained in:
Shannon Booth 2024-08-07 03:06:57 +12:00 committed by Tim Ledbetter
parent db3f118046
commit 6cac2981fb
Notes: github-actions[bot] 2024-08-06 22:09:02 +00:00
3 changed files with 5 additions and 1 deletions

View file

@ -1,2 +1,4 @@
new URL('file://xn--/p', undefined)
error creating URL: 'TypeError: Invalid URL'
new URL('http://0xffffffff1', undefined)
error creating URL: 'TypeError: Invalid URL'

View file

@ -3,6 +3,7 @@
test(() => {
const urls = [
{ input: 'file://xn--/p' },
{ input: 'http://0xffffffff1' },
];
for (url of urls) {

View file

@ -583,7 +583,8 @@ static bool ends_in_a_number_checker(StringView input)
return true;
// 5. If parsing last as an IPv4 number does not return failure, then return true.
if (parse_ipv4_number(last).has_value())
// NOTE: This is equivalent to checking that last is "0X" or "0x", followed by zero or more ASCII hex digits.
if (last.starts_with("0x"sv, CaseSensitivity::CaseInsensitive) && all_of(last.substring_view(2), is_ascii_hex_digit))
return true;
// 6. Return false.