Skip to content

Commit a624579

Browse files
committed
phar: Fix SplFileInfo::openFile() in write mode
This stopped working after e735d2b because fp_refcount is increased, making phar think that the file has open read pointers. To fix this, the refcount shouldn't be increased but that would re-introduce the previous bug. However, 6fe40de fixed a bug that makes us hold onto the phar archive too. That fix also fixes the original issue, so we can just remove the fp_refcount modification.
1 parent 37e61a0 commit a624579

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ext/phar/phar_object.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,7 +4492,6 @@ PHP_METHOD(PharFileInfo, __construct)
44924492

44934493
entry_obj->entry = entry_info;
44944494
if (!entry_info->is_persistent && !entry_info->is_temp_dir) {
4495-
++entry_info->fp_refcount;
44964495
/* The phar data must exist to keep the alias locked. */
44974496
ZEND_ASSERT(!phar_data->is_persistent);
44984497
++phar_data->refcount;
@@ -4540,7 +4539,6 @@ PHP_METHOD(PharFileInfo, __destruct)
45404539
efree(entry);
45414540
entry_obj->entry = NULL;
45424541
} else if (!entry->is_persistent) {
4543-
--entry->fp_refcount;
45444542
/* The entry itself still lives in the manifest,
45454543
* which will either be freed here if the file info was the last reference; or freed later. */
45464544
entry_obj->entry = NULL;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
SplFileInfo::openFile() in write mode
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--FILE--
8+
<?php
9+
10+
$phar = new Phar(__DIR__.'/SplFileInfo_openFile_write.phar');
11+
$phar->addFromString('test', 'contents');
12+
var_dump($phar['test']->openFile('w'));
13+
14+
?>
15+
--CLEAN--
16+
<?php
17+
@unlink(__DIR__.'/SplFileInfo_openFile_write.phar');
18+
?>
19+
--EXPECTF--
20+
object(SplFileObject)#%d (%d) {
21+
["pathName":"SplFileInfo":private]=>
22+
string(%d) "phar://%stest"
23+
["fileName":"SplFileInfo":private]=>
24+
string(4) "test"
25+
["openMode":"SplFileObject":private]=>
26+
string(1) "w"
27+
["delimiter":"SplFileObject":private]=>
28+
string(1) ","
29+
["enclosure":"SplFileObject":private]=>
30+
string(1) """
31+
}

0 commit comments

Comments
 (0)