Skip to content

Commit b77b505

Browse files
iliaalGirgias
authored andcommitted
phar: restore is_link handler in phar_intercept_functions_shutdown
phar_intercept_functions_init hooks 22 built-in functions via PHAR_INTERCEPT. phar_intercept_functions_shutdown restores all of them via PHAR_RELEASE except is_link, which was simply missing from the list. On MSHUTDOWN the is_link entry in CG(function_table) retains the phar intercept handler. In a persistent SAPI, if the module is reloaded, the second MINIT saves PHP_FN(phar_is_link) as orig_is_link, and any subsequent is_link() call recurses infinitely. Closes GH-21800
1 parent 46286fb commit b77b505

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

ext/phar/func_interceptors.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ void phar_intercept_functions_shutdown(void)
932932
PHAR_RELEASE(fopen);
933933
PHAR_RELEASE(file_get_contents);
934934
PHAR_RELEASE(is_file);
935+
PHAR_RELEASE(is_link);
935936
PHAR_RELEASE(is_dir);
936937
PHAR_RELEASE(opendir);
937938
PHAR_RELEASE(file_exists);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
phar: is_link() intercept correctly delegates for non-symlink phar entries
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
phar.require_hash=0
8+
--FILE--
9+
<?php
10+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
11+
$phar = new Phar($fname);
12+
$phar->addFromString('file.txt', 'hello');
13+
$phar->setStub('<?php
14+
Phar::interceptFileFuncs();
15+
echo "regular entry (not a symlink): ";
16+
var_dump(is_link("file.txt"));
17+
echo "missing entry: ";
18+
var_dump(is_link("nonexistent.txt"));
19+
echo "absolute phar:// path (bypasses intercept): ";
20+
var_dump(is_link("phar://" . __FILE__ . "/file.txt"));
21+
__HALT_COMPILER(); ?>');
22+
include $fname;
23+
?>
24+
--CLEAN--
25+
<?php @unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
26+
--EXPECT--
27+
regular entry (not a symlink): bool(false)
28+
missing entry: bool(false)
29+
absolute phar:// path (bypasses intercept): bool(false)

0 commit comments

Comments
 (0)