[php-src] PHP-8.4: Fix opcache phar check

From: Date: Sun, 01 Nov 2026 16:30:29 +0000
Subject: [php-src] PHP-8.4: Fix opcache phar check
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143166@lists.php.net to get a copy of this message
Author: ndossche (ndossche) Date: 2026-11-01T17:28:40+01:00 Commit: https://github.com/php/php-src/commit/cbd65db2af75931436f49b947ec8ccc37e5c5313 Raw diff: https://github.com/php/php-src/commit/cbd65db2af75931436f49b947ec8ccc37e5c5313.diff Fix opcache phar check This is the cause of the flaky nightly failures on PPC for issue0149.phpt. On slow machines, enough time passes that request 2/3 are served from opcache rather than from the disk. If we set opcache.file_update_protection=0, then the failure reproduces predictably. The root cause is that the phar check in opcache only checks if the filename ends in .phar whereas ext/phar checks whether .phar is anywhere in the filename. This difference causes requests from the cache to not execute the stub, and therefore not execute the Phar::mount() call in the test, and therefore fail the expectation. Closes GH-25128. Changed paths: M NEWS M ext/opcache/ZendAccelerator.c M ext/opcache/tests/issue0149.phpt Diff: diff --git a/NEWS b/NEWS index d23571a751f4..4cedc01bcf4e 100644 --- a/NEWS +++ b/NEWS @@ -217,6 +217,7 @@ PHP NEWS (Jorg Sowa) . Fixed bug GH-24988 (Incorrect opcode range check causes bugs with exceptions in function JIT). (ndossche, Jorg Sowa) + . Fix opcache phar check. (ndossche) - OpenSSL: . Fixed bug GH-24784 (openssl_pkcs7_read() and openssl_cms_read() overwrite diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 4df75049e172..e56904d7efb8 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -1517,10 +1517,10 @@ 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(zend_string *filename) { - return filename && ZSTR_LEN(filename) >= sizeof(".phar") && - !memcmp(ZSTR_VAL(filename) + ZSTR_LEN(filename) - (sizeof(".phar")-1), ".phar", sizeof(".phar")-1) && + return filename && strstr(ZSTR_VAL(filename), ".phar") && !strstr(ZSTR_VAL(filename), "://"); } diff --git a/ext/opcache/tests/issue0149.phpt b/ext/opcache/tests/issue0149.phpt index 29e6f02808a7..20fe7636ff08 100644 --- a/ext/opcache/tests/issue0149.phpt +++ b/ext/opcache/tests/issue0149.phpt @@ -22,7 +22,7 @@ unset($p); include "php_cli_server.inc"; -$ini = '-d opcache.enable=1 -d opcache.enable_cli=1'; +$ini = '-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.file_update_protection=0'; if (file_exists(ini_get('extension_dir').'/phar.'.PHP_SHLIB_SUFFIX)) { $ini .= ' -d extension=phar.'.PHP_SHLIB_SUFFIX; }

« previous php.cvs (#143166) next »