]> granicus.if.org Git - php/commitdiff
Fix Bug #79296 ZipArchive::open fails on empty file
authorRemi Collet <remi@remirepo.net>
Thu, 19 Mar 2020 16:31:17 +0000 (17:31 +0100)
committerRemi Collet <remi@php.net>
Fri, 20 Mar 2020 10:14:58 +0000 (11:14 +0100)
ext/zip/php_zip.c

index f65f70621e84f52308e9b872583420cf45ec0658..48af712b9c23b05066c193bb98ac9a401e7f5559 100644 (file)
@@ -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);