[php-src] PHP-8.5: Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range

From: Date: Fri, 30 Oct 2026 13:59:08 +0000
Subject: [php-src] PHP-8.5: Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143002@lists.php.net to get a copy of this message
Author: lazerg (lazerg) Committer: Máté Kocsis (kocsismate) Date: 2026-10-30T14:55:46+01:00 Commit: https://github.com/php/php-src/commit/c95e572696986461014e9743de7393f112b9c983 Raw diff: https://github.com/php/php-src/commit/c95e572696986461014e9743de7393f112b9c983.diff Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range Changed paths: A ext/uri/tests/rfc3986/parsing/port_success_leading_zeros.phpt A ext/uri/tests/rfc3986/parsing/port_success_leading_zeros_zero.phpt M NEWS M ext/uri/uri_parser_rfc3986.c Diff: diff --git a/NEWS b/NEWS index 4db408f87722..939a9aa8b0d5 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 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-- +<?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 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-- +<?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 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; }

« previous php.cvs (#143002) next »