From af05937437cdf165ec4c8ced0591cef862d3fa73 Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 29 Oct 2026 06:24:24 +0500 Subject: [PATCH 1/2] Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range --- .../parsing/port_success_leading_zeros.phpt | 33 +++++++++++++++++++ ext/uri/uri_parser_rfc3986.c | 5 +++ 2 files changed, 38 insertions(+) create mode 100644 ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt diff --git a/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt new file mode 100644 index 000000000000..e3578fdc56ca --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - port - leading zeros +--FILE-- +toRawString()); +var_dump($uri->toString()); + +?> +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(8080) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} +string(43) "http://example.com:000000000000000000008080" +string(23) "http://example.com:8080" diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c index d56d053aae58..7fd2102b28a3 100644 --- a/ext/uri/uri_parser_rfc3986.c +++ b/ext/uri/uri_parser_rfc3986.c @@ -334,6 +334,11 @@ static zend_result php_uri_parser_rfc3986_host_write(void *uri, zval *value, zva ZEND_ATTRIBUTE_NONNULL static zend_long port_str_to_zend_long_checked(const char *str, size_t len) { + while (len > 1 && *str == '0') { + str++; + len--; + } + if (len > MAX_LENGTH_OF_LONG) { return -1; } From 86ec6e203749505d62c6c5ae6eb3a25ad1710004 Mon Sep 17 00:00:00 2001 From: lazerg Date: Thu, 29 Oct 2026 12:57:12 +0500 Subject: [PATCH 2/2] Add test for a long port containing only zeros --- .../port_success_leading_zeros_zero.phpt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt diff --git a/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt new file mode 100644 index 000000000000..75796ddb9c65 --- /dev/null +++ b/ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test Uri\Rfc3986\Uri parsing - port - leading zeros - zero +--FILE-- +toRawString()); +var_dump($uri->toString()); + +?> +--EXPECTF-- +object(Uri\Rfc3986\Uri)#%d (%d) { + ["scheme"]=> + string(4) "http" + ["username"]=> + NULL + ["password"]=> + NULL + ["host"]=> + string(11) "example.com" + ["port"]=> + int(0) + ["path"]=> + string(0) "" + ["query"]=> + NULL + ["fragment"]=> + NULL +} +string(43) "http://example.com:000000000000000000000000" +string(20) "http://example.com:0"