com php-src: Fix phar:// include handling with file cache: ext/opcache/zend_file_cache.c ext/phar/tests/024- opcache-win32.phpt

From: Date: Wed, 10 Apr 2019 12:55:15 +0000
Subject: com php-src: Fix phar:// include handling with file cache: ext/opcache/zend_file_cache.c ext/phar/tests/024- opcache-win32.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-105625@lists.php.net to get a copy of this message
Commit: f31d7ca85e400b85c06adb8db24c573dc1d98dbb Author: Anatol Belski <ab@php.net> Wed, 10 Apr 2019 14:55:15 +0200 Parents: 8f13599a645a97df940640e9c70f164a92e8743c Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f31d7ca85e400b85c06adb8db24c573dc1d98dbb Log: Fix phar:// include handling with file cache Changed paths: M ext/opcache/zend_file_cache.c A ext/phar/tests/024-opcache-win32.phpt Diff: diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 6261e82..c00f153 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -775,7 +775,21 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path) filename[len] = '\\'; memcpy(filename + len + 1, ZCG(system_id), 32); - if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) { + + if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5] && '/' == ZSTR_VAL(script_path)[6]) { + /* phar:// or file:// */ + *(filename + len + 33) = '\\'; + memcpy(filename + len + 34, ZSTR_VAL(script_path), 4); + if (ZSTR_LEN(script_path) - 7 >= 2 && ':' == ZSTR_VAL(script_path)[8]) { + *(filename + len + 38) = '\\'; + *(filename + len + 39) = ZSTR_VAL(script_path)[7]; + memcpy(filename + len + 40, ZSTR_VAL(script_path) + 9, ZSTR_LEN(script_path) - 9); + memcpy(filename + len + 40 + ZSTR_LEN(script_path) - 9, SUFFIX, sizeof(SUFFIX)); + } else { + memcpy(filename + len + 38, ZSTR_VAL(script_path) + 7, ZSTR_LEN(script_path) - 7); + memcpy(filename + len + 38 + ZSTR_LEN(script_path) - 7, SUFFIX, sizeof(SUFFIX)); + } + } else if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) { /* local fs */ *(filename + len + 33) = '\\'; *(filename + len + 34) = ZSTR_VAL(script_path)[0]; diff --git a/ext/phar/tests/024-opcache-win32.phpt b/ext/phar/tests/024-opcache-win32.phpt new file mode 100644 index 0000000..81eedd9 --- /dev/null +++ b/ext/phar/tests/024-opcache-win32.phpt @@ -0,0 +1,61 @@ +--TEST-- +Phar: phar:// include with Opcache +--SKIPIF-- +<?php if (strpos(PHP_OS, 'WIN') === false) die("skip Extra warning on Windows."); ?> +<?php if (!extension_loaded("phar")) die("skip"); ?> +<?php if (!extension_loaded('Zend OPcache')) die('skip Zend OPcache extension not available'); ?> +<?php + $cache_dir = dirname(__FILE__) . "/024-file_cache"; + if (!is_dir($cache_dir) && !mkdir($cache_dir)) die("skip unable to create file_cache dir"); +?> +--INI-- +phar.require_hash=0 +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_cache={PWD}/024-file_cache +opcache.memory_consumption=64 +opcache.interned_strings_buffer=8 +opcache.max_accelerated_files=4000 +opcache.jit_buffer_size=6M +opcache.revalidate_freq=60 +opcache.fast_shutdown=1 +--FILE-- +<?php + +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$pname = 'phar://' . $fname; +$file = "<?php __HALT_COMPILER(); ?>"; + +$files = array(); +$files['a.php'] = '<?php echo "This is a\n"; ?>'; +$files['b.php'] = '<?php echo "This is b\n"; ?>'; +$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>'; + +include 'files/phar_test.inc'; + +include $pname . '/a.php'; +include $pname . '/b.php'; +include $pname . '/b/c.php'; + +$cache_dir = ini_get("opcache.file_cache"); +if (is_dir($cache_dir)) { + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($cache_dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($it as $fi) { + $fn = ($fi->isDir() ? 'rmdir' : 'unlink'); + $fn($fi->getRealPath()); + } + + rmdir($cache_dir); +} + +?> +===DONE=== +--CLEAN-- +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> +--EXPECT-- +This is a +This is b +This is b/c +===DONE===

« previous php.cvs (#105625) next »