From 8aab43c85d67fc1c1935f91bc64db800c4ef4754 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 19 Mar 2020 17:31:17 +0100 Subject: [PATCH 1/2] Fix Bug #79296 ZipArchive::open fails on empty file --- ext/zip/php_zip.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index f65f70621e8..48af712b9c2 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1480,6 +1480,21 @@ static ZIPARCHIVE_METHOD(open) ze_obj->filename = NULL; } +#if LIBZIP_VERSION_MAJOR > 1 || LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR >= 6 + /* reduce BC break introduce in libzip 1.6.0 + "Do not accept empty files as valid zip archives any longer" */ + + /* open for write without option to empty the archive */ + if ((flags & (ZIP_TRUNCATE | ZIP_RDONLY)) == 0) { + zend_stat_t st; + + /* exists and is empty */ + if (VCWD_STAT(resolved_path, &st) == 0 && st.st_size == 0) { + flags |= ZIP_TRUNCATE; + } + } +#endif + intern = zip_open(resolved_path, flags, &err); if (!intern || err) { efree(resolved_path); From 51c57a9c677f81bf70e64b2b10d44d04d2cdf0ea Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 20 Mar 2020 11:16:08 +0100 Subject: [PATCH 2/2] NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 4778a5c5546..5cc62b59b32 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,9 @@ PHP NEWS - Spl: . Fixed bug #75673 (SplStack::unserialize() behavior). (cmb) +- Zip: + . Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi) + 19 Mar 2020, PHP 7.3.16 - Core: