Commit 09ea5374b10 for php
commit 09ea5374b10ad0d78699b9f31cc6bd28ccd1515c
Author: Máté Kocsis <kocsismate@woohoolabs.com>
Date: Tue Dec 1 22:28:53 2026 +0100
ext/uri: Optimize GHSA-mg3p-mxj9-g2mm tests (#25818)
Changing the input URI to a relative path reference makes the tests much faster, because uriparser only increases a pointer for each character while parsing the beginning of a URI while it's not yet known if the current component is a scheme or a path. On the other hand, uriparser calls a `URI_FUNC(ParsePchar)` function for each character while parsing the path after a "/" character (in case of absolute URIs, or absolute path references).
Additionally, the strspn() call is replaced with strcmp() because strspn() was also slow.
I tested the performance of my changes on Mac OS with ASAN, and the execution time of the first two tests decreased by ~40%, while GHSA-mg3p-mxj9-g2mm-3.phpt decreased by ~70%.
diff --git a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-1.phpt b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-1.phpt
index 57e9e9947d4..28cd3920e2c 100644
--- a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-1.phpt
+++ b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-1.phpt
@@ -16,7 +16,8 @@
memory_limit=-1
--FILE--
<?php
-$uri = new Uri\Rfc3986\Uri("a://b/" . str_repeat("x", 2147483647 - 6));
+// Parsing a single relative path segment is cheap under sanitizers.
+$uri = new Uri\Rfc3986\Uri(str_repeat("x", 2147483647));
try {
$uri->toRawString();
diff --git a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-2.phpt b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-2.phpt
index 60755a914df..47c8c613296 100644
--- a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-2.phpt
+++ b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-2.phpt
@@ -16,7 +16,8 @@
memory_limit=-1
--FILE--
<?php
-$uri = new Uri\Rfc3986\Uri("a://b/" . str_repeat("x", 2147483648 - 6));
+// Keep the length of each path segment below the 32-bit INT_MAX that uriparser uses while the recomposed path exceeds it.
+$uri = new Uri\Rfc3986\Uri(str_repeat("x", 2147483648 - 2) . "/x");
try {
$uri->toRawString();
diff --git a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-3.phpt b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-3.phpt
index 199515635b1..ecfe6cb2db7 100644
--- a/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-3.phpt
+++ b/ext/uri/tests/rfc3986/general/GHSA-mg3p-mxj9-g2mm-3.phpt
@@ -16,14 +16,15 @@
memory_limit=-1
--FILE--
<?php
-$uri = new Uri\Rfc3986\Uri("a://b/" . str_repeat("x", 2147483646 - 6));
-$string = $uri->toRawString();
+$length = 2147483646; // 32-bit INT_MAX - 1
+
+// Parsing a single relative path segment is cheap under sanitizers.
+$string = (new Uri\Rfc3986\Uri(str_repeat("x", $length)))->toRawString();
+
var_dump(strlen($string));
-var_dump(substr($string, 0, 8));
-var_dump(strspn($string, "x", 6) === 2147483646 - 6);
+var_dump($string === str_repeat("x", $length));
?>
--EXPECT--
int(2147483646)
-string(8) "a://b/xx"
bool(true)