Skip to content

Commit

Permalink
Merge branch 'PHP-8.3' into PHP-8.4
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix GH-17808: PharFileInfo refcount bug
  • Loading branch information
nielsdos committed Feb 15, 2025
2 parents eabbb1c + e735d2b commit 5d8ea65
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ PHP NEWS
. Fixed bug GH-17747 (Exception on reading property in register-based
FETCH_OBJ_R breaks JIT). (Dmitry, nielsdos)

- Phar:
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)

- PHPDBG:
. Partially fixed bug GH-17387 (Trivial crash in phpdbg lexer). (nielsdos)
. Fix memory leak in phpdbg calling registered function. (nielsdos)
Expand Down
15 changes: 13 additions & 2 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -4510,6 +4510,9 @@ PHP_METHOD(PharFileInfo, __construct)
efree(entry);

entry_obj->entry = entry_info;
if (!entry_info->is_persistent && !entry_info->is_temp_dir) {
++entry_info->fp_refcount;
}

ZVAL_STRINGL(&arg1, fname, fname_len);

Expand Down Expand Up @@ -4539,15 +4542,23 @@ PHP_METHOD(PharFileInfo, __destruct)
RETURN_THROWS();
}

if (entry_obj->entry && entry_obj->entry->is_temp_dir) {
if (!entry_obj->entry) {
return;
}

if (entry_obj->entry->is_temp_dir) {
if (entry_obj->entry->filename) {
efree(entry_obj->entry->filename);
entry_obj->entry->filename = NULL;
}

efree(entry_obj->entry);
entry_obj->entry = NULL;
} else if (!entry_obj->entry->is_persistent) {
--entry_obj->entry->fp_refcount;
/* It is necessarily still in the manifest, which will ultimately free this. */
}

entry_obj->entry = NULL;
}
/* }}} */

Expand Down
21 changes: 21 additions & 0 deletions ext/phar/tests/gh17808.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-17808 (PharFileInfo refcount bug)
--EXTENSIONS--
phar
--FILE--
<?php
$fname = __DIR__.'/tar/files/Structures_Graph-1.0.3.tgz';
$tar = new PharData($fname);
foreach (new RecursiveIteratorIterator($tar) as $file) {
}
var_dump("$file");
var_dump(strlen($file->getContent()));
unlink("$file");
var_dump($file->getATime());
?>
--EXPECTF--
string(%d) "phar://%spackage.xml"
int(6747)

Warning: unlink(): phar error: "package.xml" in phar %s, has open file pointers, cannot unlink in %s on line %d
int(33188)

0 comments on commit 5d8ea65

Please sign in to comment.