Commit c95e5726969 for php
commit c95e572696986461014e9743de7393f112b9c983
Author: lazerg <lazerg2@gmail.com>
Date: Thu Oct 29 06:24:24 2026 +0500
Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range
diff --git a/NEWS b/NEWS
index 4db408f8772..939a9aa8b0d 100644
--- a/NEWS
+++ b/NEWS
@@ -265,6 +265,10 @@ PHP NEWS
. Fixed tidy_repair_string(), tidy_repair_file(), tidy::repairString() and
tidy::repairFile() rejecting null for $encoding. (lacatoire)
+- URI:
+ . Fixed bug GH-25019 (Uri\Rfc3986\Uri rejects a port with leading zeros as
+ out of range). (lazerg)
+
- Zip:
. Reject broken libzip versions 1.3.1, 1.7.0 and 1.12.0 during Windows
configuration. (Weilin Du)
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 00000000000..e3578fdc56c
--- /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--
+<?php
+
+$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000008080");
+
+var_dump($uri);
+var_dump($uri->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/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 00000000000..75796ddb9c6
--- /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--
+<?php
+
+$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000000000");
+
+var_dump($uri);
+var_dump($uri->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"
diff --git a/ext/uri/uri_parser_rfc3986.c b/ext/uri/uri_parser_rfc3986.c
index d56d053aae5..7fd2102b28a 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;
}