Skip to content

Commit 5d8ea65

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17808: PharFileInfo refcount bug
2 parents eabbb1c + e735d2b commit 5d8ea65

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ PHP NEWS
4949
. Fixed bug GH-17747 (Exception on reading property in register-based
5050
FETCH_OBJ_R breaks JIT). (Dmitry, nielsdos)
5151

52+
- Phar:
53+
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)
54+
5255
- PHPDBG:
5356
. Partially fixed bug GH-17387 (Trivial crash in phpdbg lexer). (nielsdos)
5457
. Fix memory leak in phpdbg calling registered function. (nielsdos)

ext/phar/phar_object.c

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

45124512
entry_obj->entry = entry_info;
4513+
if (!entry_info->is_persistent && !entry_info->is_temp_dir) {
4514+
++entry_info->fp_refcount;
4515+
}
45134516

45144517
ZVAL_STRINGL(&arg1, fname, fname_len);
45154518

@@ -4539,15 +4542,23 @@ PHP_METHOD(PharFileInfo, __destruct)
45394542
RETURN_THROWS();
45404543
}
45414544

4542-
if (entry_obj->entry && entry_obj->entry->is_temp_dir) {
4545+
if (!entry_obj->entry) {
4546+
return;
4547+
}
4548+
4549+
if (entry_obj->entry->is_temp_dir) {
45434550
if (entry_obj->entry->filename) {
45444551
efree(entry_obj->entry->filename);
45454552
entry_obj->entry->filename = NULL;
45464553
}
45474554

45484555
efree(entry_obj->entry);
4549-
entry_obj->entry = NULL;
4556+
} else if (!entry_obj->entry->is_persistent) {
4557+
--entry_obj->entry->fp_refcount;
4558+
/* It is necessarily still in the manifest, which will ultimately free this. */
45504559
}
4560+
4561+
entry_obj->entry = NULL;
45514562
}
45524563
/* }}} */
45534564

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)