From a375b5a2d98720a9bb8872c8c123925b889cb1ec Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 20 Jan 2021 14:18:36 +0100 Subject: [PATCH 1/2] Fix #80648: Fix for bug 79296 should be based on runtime version --- ext/zip/php_zip.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 883b6f6d40a1..960d941a2982 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1473,17 +1473,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; +#ifdef HAVE_LIBZIP_VERSION + /* zip_libzip_version() is available as of 1.3.1; + older versions don't need a workaround */ + if (php_version_compare(zip_libzip_version(), "1.6.0") >= 0) { + /* reduce BC break introduced 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 From 99a1eff0619205486e4cb75624e89d915812060f Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 20 Jan 2021 15:24:47 +0100 Subject: [PATCH 2/2] Always ZIP_TRUNCATE empty files unless ZIP_RDONLY is set --- ext/zip/php_zip.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 960d941a2982..21182068d1d7 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1473,24 +1473,21 @@ static ZIPARCHIVE_METHOD(open) ze_obj->filename = NULL; } -#ifdef HAVE_LIBZIP_VERSION - /* zip_libzip_version() is available as of 1.3.1; - older versions don't need a workaround */ - if (php_version_compare(zip_libzip_version(), "1.6.0") >= 0) { - /* reduce BC break introduced 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; - } + /* open for write without option to empty the archive */ +#ifdef ZIP_RDONLY + if ((flags & (ZIP_TRUNCATE | ZIP_RDONLY)) == 0) { +#else + if ((flags & ZIP_TRUNCATE) == 0) { +#endif + zend_stat_t st; + + /* exists and is empty */ + if (VCWD_STAT(resolved_path, &st) == 0 && st.st_size == 0) { + /* reduce BC break introduced in libzip 1.6.0 + "Do not accept empty files as valid zip archives any longer" */ + flags |= ZIP_TRUNCATE; } } -#endif intern = zip_open(resolved_path, flags, &err); if (!intern || err) {