Skip to content

Commit c7d62cf

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17808: PharFileInfo refcount bug
2 parents a570ce8 + 5d8ea65 commit c7d62cf

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ext/phar/phar_object.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,6 +4504,9 @@ PHP_METHOD(PharFileInfo, __construct)
45044504
efree(entry);
45054505

45064506
entry_obj->entry = entry_info;
4507+
if (!entry_info->is_persistent && !entry_info->is_temp_dir) {
4508+
++entry_info->fp_refcount;
4509+
}
45074510

45084511
ZVAL_STRINGL(&arg1, fname, fname_len);
45094512

@@ -4533,15 +4536,23 @@ PHP_METHOD(PharFileInfo, __destruct)
45334536
RETURN_THROWS();
45344537
}
45354538

4536-
if (entry_obj->entry && entry_obj->entry->is_temp_dir) {
4539+
if (!entry_obj->entry) {
4540+
return;
4541+
}
4542+
4543+
if (entry_obj->entry->is_temp_dir) {
45374544
if (entry_obj->entry->filename) {
45384545
zend_string_efree(entry_obj->entry->filename);
45394546
entry_obj->entry->filename = NULL;
45404547
}
45414548

45424549
efree(entry_obj->entry);
4543-
entry_obj->entry = NULL;
4550+
} else if (!entry_obj->entry->is_persistent) {
4551+
--entry_obj->entry->fp_refcount;
4552+
/* It is necessarily still in the manifest, which will ultimately free this. */
45444553
}
4554+
4555+
entry_obj->entry = NULL;
45454556
}
45464557
/* }}} */
45474558

ext/phar/tests/gh17808.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-17808 (PharFileInfo refcount bug)
3+
--EXTENSIONS--
4+
phar
5+
--FILE--
6+
<?php
7+
$fname = __DIR__.'/tar/files/Structures_Graph-1.0.3.tgz';
8+
$tar = new PharData($fname);
9+
foreach (new RecursiveIteratorIterator($tar) as $file) {
10+
}
11+
var_dump("$file");
12+
var_dump(strlen($file->getContent()));
13+
unlink("$file");
14+
var_dump($file->getATime());
15+
?>
16+
--EXPECTF--
17+
string(%d) "phar://%spackage.xml"
18+
int(6747)
19+
20+
Warning: unlink(): phar error: "package.xml" in phar %s, has open file pointers, cannot unlink in %s on line %d
21+
int(33188)

0 commit comments

Comments
 (0)