Skip to content

Commit c76374d

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: NEWS Fix GH-8781 ZipArchive::close deletes zip file without updating stat cache
2 parents 971b07e + 26feb2e commit c76374d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ext/zip/php_zip.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,9 @@ PHP_METHOD(ZipArchive, close)
15711571
ze_obj->err_sys = 0;
15721572
}
15731573

1574+
/* clear cache as empty zip are not created but deleted */
1575+
php_clear_stat_cache(1, ze_obj->filename, ze_obj->filename_len);
1576+
15741577
efree(ze_obj->filename);
15751578
ze_obj->filename = NULL;
15761579
ze_obj->filename_len = 0;

ext/zip/tests/bug_gh8781.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug GH-8781 (ZipArchive deletes zip file with no contents)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zip')) die('skip zip extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
touch($file = __DIR__ . '/bug_gh8781.zip');
10+
var_dump(is_file($file));
11+
12+
$zip = new ZipArchive();
13+
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
14+
$zip->close();
15+
16+
var_dump(is_file($file));
17+
?>
18+
--EXPECT--
19+
bool(true)
20+
bool(false)
21+

0 commit comments

Comments
 (0)