Commit 4c54dce2bc2 for php.net
commit 4c54dce2bc252315dbf3c524929a8d8edf5bbef4
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date: Sat Jun 6 10:06:01 2026 +0200
zip: Fix file descriptor leak when php_zip_add_file() fails
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index d25cfe04326..a1c92203dff 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -313,11 +313,15 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
}
flags ^= ZIP_FL_OPEN_FILE_NOW;
zs = zip_source_filep(obj->za, fd, offset_start, offset_len);
+ if (!zs) {
+ fclose(fd);
+ return FAILURE;
+ }
} else {
zs = zip_source_file(obj->za, resolved_path, offset_start, offset_len);
- }
- if (!zs) {
- return -1;
+ if (!zs) {
+ return FAILURE;
+ }
}
/* Replace */
if (replace >= 0) {