Skip to content

Commit

Permalink
Fix GH-8781 ZipArchive::close deletes zip file without updating stat …
Browse files Browse the repository at this point in the history
…cache
  • Loading branch information
remicollet committed Jun 15, 2022
1 parent 1cd8074 commit 390538a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/zip/php_zip.c
Expand Up @@ -1562,6 +1562,9 @@ PHP_METHOD(ZipArchive, close)
ze_obj->err_sys = 0;
}

/* clear cache as empty zip are not created but deleted */
php_clear_stat_cache(1, ze_obj->filename, ze_obj->filename_len);

efree(ze_obj->filename);
ze_obj->filename = NULL;
ze_obj->filename_len = 0;
Expand Down
21 changes: 21 additions & 0 deletions ext/zip/tests/bug_gh8781.phpt
@@ -0,0 +1,21 @@
--TEST--
Bug GH-8781 (ZipArchive deletes zip file with no contents)
--SKIPIF--
<?php
if (!extension_loaded('zip')) die('skip zip extension not available');
?>
--FILE--
<?php
touch($file = __DIR__ . '/bug_gh8781.zip');
var_dump(is_file($file));

$zip = new ZipArchive();
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->close();

var_dump(is_file($file));
?>
--EXPECT--
bool(true)
bool(false)

0 comments on commit 390538a

Please sign in to comment.