diff options
author | Remi Collet <remi@remirepo.net> | 2020-03-19 17:31:17 +0100 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2020-03-20 11:14:58 +0100 |
commit | 8aab43c85d67fc1c1935f91bc64db800c4ef4754 (patch) | |
tree | 3aec41c42e2e27056802e782332d365613308e2c | |
parent | d70058a139f3a45898e1f270c840fb64ea1a09f0 (diff) | |
download | php-git-8aab43c85d67fc1c1935f91bc64db800c4ef4754.tar.gz |
Fix Bug #79296 ZipArchive::open fails on empty file
-rw-r--r-- | ext/zip/php_zip.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index f65f70621e..48af712b9c 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); |