Skip to content

Commit 8aab43c

Browse files
committed
Fix Bug #79296 ZipArchive::open fails on empty file
1 parent d70058a commit 8aab43c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/zip/php_zip.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,21 @@ static ZIPARCHIVE_METHOD(open)
14801480
ze_obj->filename = NULL;
14811481
}
14821482

1483+
#if LIBZIP_VERSION_MAJOR > 1 || LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR >= 6
1484+
/* reduce BC break introduce in libzip 1.6.0
1485+
"Do not accept empty files as valid zip archives any longer" */
1486+
1487+
/* open for write without option to empty the archive */
1488+
if ((flags & (ZIP_TRUNCATE | ZIP_RDONLY)) == 0) {
1489+
zend_stat_t st;
1490+
1491+
/* exists and is empty */
1492+
if (VCWD_STAT(resolved_path, &st) == 0 && st.st_size == 0) {
1493+
flags |= ZIP_TRUNCATE;
1494+
}
1495+
}
1496+
#endif
1497+
14831498
intern = zip_open(resolved_path, flags, &err);
14841499
if (!intern || err) {
14851500
efree(resolved_path);

0 commit comments

Comments
 (0)