Skip to content

Commit 390538a

Browse files
committed
Fix GH-8781 ZipArchive::close deletes zip file without updating stat cache
1 parent 1cd8074 commit 390538a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ext/zip/php_zip.c

+3
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,9 @@ PHP_METHOD(ZipArchive, close)
15621562
ze_obj->err_sys = 0;
15631563
}
15641564

1565+
/* clear cache as empty zip are not created but deleted */
1566+
php_clear_stat_cache(1, ze_obj->filename, ze_obj->filename_len);
1567+
15651568
efree(ze_obj->filename);
15661569
ze_obj->filename = NULL;
15671570
ze_obj->filename_len = 0;

ext/zip/tests/bug_gh8781.phpt

+21
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)