diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index e2f36f1c7b24..cb071f0ca300 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -784,7 +784,7 @@ PHP_METHOD(Phar, webPhar) sapi_header_op(SAPI_HEADER_REPLACE, &ctr); if (not_cgi) { - tmp = strstr(path_info, basename) + fname_len; + tmp = strstr(path_info, basename) + (fname_len - (basename - fname)); sa = *tmp; *tmp = '\0'; } diff --git a/ext/phar/tests/gh25093.phpt b/ext/phar/tests/gh25093.phpt new file mode 100644 index 000000000000..442a95e63c7a --- /dev/null +++ b/ext/phar/tests/gh25093.phpt @@ -0,0 +1,47 @@ +--TEST-- +GH-25093: Phar::webPhar() redirect reads past the request URI +--EXTENSIONS-- +phar +--SKIPIF-- + +--CONFLICTS-- +server +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +docRoot . '/gh25093.phar'); +$phar->addFromString('index.php', 'setStub(''); +unset($phar); + +$context = stream_context_create(['http' => ['follow_location' => 0]]); +$uri = '/gh25093.phar/' . str_repeat('a', strlen($info->docRoot) + 32); +file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . $uri, false, $context); + +foreach (http_get_last_response_headers() as $header) { + if (str_starts_with($header, 'Location: ')) { + echo $header, "\n"; + } +} +?> +--EXPECT-- +Location: /gh25093.phar/index.php