Skip to content

ext/uri: Optimize GHSA-mg3p-mxj9-g2mm tests - #25818

Open
kocsismate wants to merge 3 commits into
php:PHP-8.5from
kocsismate:uri-ghsa-test-optimization
Open

kocsismate wants to merge 3 commits into
php:PHP-8.5from
kocsismate:uri-ghsa-test-optimization

Conversation

@kocsismate

@kocsismate kocsismate commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

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%.

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%.
@kocsismate
kocsismate force-pushed the uri-ghsa-test-optimization branch from ff38adc to d32a3c1 Compare November 27, 2026 12:23
@kocsismate
kocsismate changed the base branch from master to PHP-8.5 November 27, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants