From 390538af2ed5cd18e3096ad70597035dbca52139 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 15 Jun 2022 08:57:17 +0200 Subject: [PATCH 1/2] Fix GH-8781 ZipArchive::close deletes zip file without updating stat cache --- ext/zip/php_zip.c | 3 +++ ext/zip/tests/bug_gh8781.phpt | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ext/zip/tests/bug_gh8781.phpt diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 14fa3e784ab..d00d050204e 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -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; diff --git a/ext/zip/tests/bug_gh8781.phpt b/ext/zip/tests/bug_gh8781.phpt new file mode 100644 index 00000000000..25eadb70575 --- /dev/null +++ b/ext/zip/tests/bug_gh8781.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-8781 (ZipArchive deletes zip file with no contents) +--SKIPIF-- + +--FILE-- +open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE); +$zip->close(); + +var_dump(is_file($file)); +?> +--EXPECT-- +bool(true) +bool(false) + From 26feb2e6f26273e3b79ef0505c073fbceac30407 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 15 Jun 2022 15:38:37 +0200 Subject: [PATCH 2/2] NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 10e0e919f0b..dfbdd981223 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,10 @@ PHP NEWS . Fixed errorInfo() result on successful PDOStatement->execute(). (Yurunsoft) . Fixed handling of single-key connection strings. (Calvin Buckley) +- Zip: + . Fixed bug GH-8781 (ZipArchive::close deletes zip file without updating stat + cache). (Remi) + 09 Jun 2022, PHP 8.0.20 - CLI: