Skip to content

Commit 98687ab

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: NEWS Fix Bug #79296 ZipArchive::open fails on empty file
2 parents 673a3ce + 51c57a9 commit 98687ab

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
@@ -1472,6 +1472,21 @@ static ZIPARCHIVE_METHOD(open)
14721472
ze_obj->filename = NULL;
14731473
}
14741474

1475+
#if LIBZIP_VERSION_MAJOR > 1 || LIBZIP_VERSION_MAJOR == 1 && LIBZIP_VERSION_MINOR >= 6
1476+
/* reduce BC break introduce in libzip 1.6.0
1477+
"Do not accept empty files as valid zip archives any longer" */
1478+
1479+
/* open for write without option to empty the archive */
1480+
if ((flags & (ZIP_TRUNCATE | ZIP_RDONLY)) == 0) {
1481+
zend_stat_t st;
1482+
1483+
/* exists and is empty */
1484+
if (VCWD_STAT(resolved_path, &st) == 0 && st.st_size == 0) {
1485+
flags |= ZIP_TRUNCATE;
1486+
}
1487+
}
1488+
#endif
1489+
14751490
intern = zip_open(resolved_path, flags, &err);
14761491
if (!intern || err) {
14771492
efree(resolved_path);

0 commit comments

Comments
 (0)