Skip to content

Commit f31d7ca

Browse files
committed
Fix phar:// include handling with file cache
1 parent 8f13599 commit f31d7ca

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,21 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
775775
filename[len] = '\\';
776776

777777
memcpy(filename + len + 1, ZCG(system_id), 32);
778-
if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) {
778+
779+
if (ZSTR_LEN(script_path) >= 7 && ':' == ZSTR_VAL(script_path)[4] && '/' == ZSTR_VAL(script_path)[5] && '/' == ZSTR_VAL(script_path)[6]) {
780+
/* phar:// or file:// */
781+
*(filename + len + 33) = '\\';
782+
memcpy(filename + len + 34, ZSTR_VAL(script_path), 4);
783+
if (ZSTR_LEN(script_path) - 7 >= 2 && ':' == ZSTR_VAL(script_path)[8]) {
784+
*(filename + len + 38) = '\\';
785+
*(filename + len + 39) = ZSTR_VAL(script_path)[7];
786+
memcpy(filename + len + 40, ZSTR_VAL(script_path) + 9, ZSTR_LEN(script_path) - 9);
787+
memcpy(filename + len + 40 + ZSTR_LEN(script_path) - 9, SUFFIX, sizeof(SUFFIX));
788+
} else {
789+
memcpy(filename + len + 38, ZSTR_VAL(script_path) + 7, ZSTR_LEN(script_path) - 7);
790+
memcpy(filename + len + 38 + ZSTR_LEN(script_path) - 7, SUFFIX, sizeof(SUFFIX));
791+
}
792+
} else if (ZSTR_LEN(script_path) >= 2 && ':' == ZSTR_VAL(script_path)[1]) {
779793
/* local fs */
780794
*(filename + len + 33) = '\\';
781795
*(filename + len + 34) = ZSTR_VAL(script_path)[0];

ext/phar/tests/024-opcache-win32.phpt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--TEST--
2+
Phar: phar:// include with Opcache
3+
--SKIPIF--
4+
<?php if (strpos(PHP_OS, 'WIN') === false) die("skip Extra warning on Windows."); ?>
5+
<?php if (!extension_loaded("phar")) die("skip"); ?>
6+
<?php if (!extension_loaded('Zend OPcache')) die('skip Zend OPcache extension not available'); ?>
7+
<?php
8+
$cache_dir = dirname(__FILE__) . "/024-file_cache";
9+
if (!is_dir($cache_dir) && !mkdir($cache_dir)) die("skip unable to create file_cache dir");
10+
?>
11+
--INI--
12+
phar.require_hash=0
13+
opcache.enable=1
14+
opcache.enable_cli=1
15+
opcache.file_cache={PWD}/024-file_cache
16+
opcache.memory_consumption=64
17+
opcache.interned_strings_buffer=8
18+
opcache.max_accelerated_files=4000
19+
opcache.jit_buffer_size=6M
20+
opcache.revalidate_freq=60
21+
opcache.fast_shutdown=1
22+
--FILE--
23+
<?php
24+
25+
$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
26+
$pname = 'phar://' . $fname;
27+
$file = "<?php __HALT_COMPILER(); ?>";
28+
29+
$files = array();
30+
$files['a.php'] = '<?php echo "This is a\n"; ?>';
31+
$files['b.php'] = '<?php echo "This is b\n"; ?>';
32+
$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
33+
34+
include 'files/phar_test.inc';
35+
36+
include $pname . '/a.php';
37+
include $pname . '/b.php';
38+
include $pname . '/b/c.php';
39+
40+
$cache_dir = ini_get("opcache.file_cache");
41+
if (is_dir($cache_dir)) {
42+
$it = new RecursiveIteratorIterator(
43+
new RecursiveDirectoryIterator($cache_dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST
44+
);
45+
foreach ($it as $fi) {
46+
$fn = ($fi->isDir() ? 'rmdir' : 'unlink');
47+
$fn($fi->getRealPath());
48+
}
49+
50+
rmdir($cache_dir);
51+
}
52+
53+
?>
54+
===DONE===
55+
--CLEAN--
56+
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
57+
--EXPECT--
58+
This is a
59+
This is b
60+
This is b/c
61+
===DONE===

0 commit comments

Comments
 (0)