From a19e38644e34199995a465a72c63bad45c9a94d3 Mon Sep 17 00:00:00 2001 From: AdamMagued Date: Thu, 5 Nov 2026 22:48:22 +0200 Subject: [PATCH] fix(opcache): harmonize is_phar_file marker check with ext/phar --- ext/opcache/ZendAccelerator.c | 22 +++++++++- ext/opcache/tests/gh25130.phpt | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 ext/opcache/tests/gh25130.phpt diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 7ea59be43821..e18e1abfca83 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1544,8 +1544,26 @@ static void zend_accel_add_key(zend_string *key, zend_accel_hash_entry *bucket) /* Must perform the same check as phar_compile_file(). */ static zend_always_inline bool is_phar_file(const zend_string *filename) { - return filename && strstr(ZSTR_VAL(filename), ".phar") && - !strstr(ZSTR_VAL(filename), "://"); + if (!filename || strstr(ZSTR_VAL(filename), "://")) { + return false; + } + + const char *path = ZSTR_VAL(filename); + const char *basename = zend_memrchr(path, '/', ZSTR_LEN(filename)); +#if defined(PHP_WIN32) || defined(ZEND_WIN32) + const char *backslash = zend_memrchr(path, '\\', ZSTR_LEN(filename)); + if (backslash && (!basename || backslash > basename)) { + basename = backslash; + } +#endif + const char *marker = basename ? basename + 1 : path; + while ((marker = strstr(marker, ".phar"))) { + marker += sizeof(".phar") - 1; + if (*marker == '\0' || *marker == '.') { + return true; + } + } + return false; } static zend_persistent_script *store_script_in_file_cache(zend_persistent_script *new_persistent_script) diff --git a/ext/opcache/tests/gh25130.phpt b/ext/opcache/tests/gh25130.phpt new file mode 100644 index 000000000000..5143f241b404 --- /dev/null +++ b/ext/opcache/tests/gh25130.phpt @@ -0,0 +1,80 @@ +--TEST-- +GH-25130: Harmonize opcache is_phar_file marker check with ext/phar +--EXTENSIONS-- +opcache +--CONFLICTS-- +server +--FILE-- + +--CLEAN-- + +--EXPECT-- +test.pharma.phar.php +test.phar.php +test.phar