Skip to content

Commit e21aaa3

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: zip: Fix leak when zip_fread() fails zip: Fix name leaks when path length check fails in php_zip_pcre() zip: Fix file descriptor leak when php_zip_add_file() fails
2 parents 0814870 + 17f6752 commit e21aaa3

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ PHP NEWS
2929
(ndossche)
3030
. Fixed memory leak in inflate_add(). (ndossche)
3131

32+
- Zip:
33+
. Fixed error-related memory leaks. (ndossche)
34+
3235
02 Jun 2026, PHP 8.5.7
3336

3437
- CLI:

ext/zip/php_zip.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,15 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
307307
}
308308
flags ^= ZIP_FL_OPEN_FILE_NOW;
309309
zs = zip_source_filep(obj->za, fd, offset_start, offset_len);
310+
if (!zs) {
311+
fclose(fd);
312+
return FAILURE;
313+
}
310314
} else {
311315
zs = zip_source_file(obj->za, resolved_path, offset_start, offset_len);
312-
}
313-
if (!zs) {
314-
return -1;
316+
if (!zs) {
317+
return FAILURE;
318+
}
315319
}
316320
/* Replace */
317321
if (replace >= 0) {
@@ -743,7 +747,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
743747
if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
744748
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %u, %zu given)",
745749
MAXPATHLEN - 1, (path_len + namelist_len + 1));
746-
zend_string_release_ex(namelist[i], 0);
750+
/* The loop isn't continued, so all remaining file names must get freed. */
751+
for (; i < files_cnt; i++) {
752+
zend_string_release_ex(namelist[i], false);
753+
}
747754
break;
748755
}
749756

@@ -2907,6 +2914,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
29072914
buffer = zend_string_safe_alloc(1, len, 0, 0);
29082915
zip_int64_t n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
29092916
if (n < 1) {
2917+
zip_fclose(zf);
29102918
zend_string_efree(buffer);
29112919
RETURN_EMPTY_STRING();
29122920
}

0 commit comments

Comments
 (0)