Skip to content

Commit 7aff22c

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: 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 ad1cf51 + e21aaa3 commit 7aff22c

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

ext/zip/php_zip.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ static zend_result php_zip_add_file(ze_zip_object *obj, const char *filename, si
309309
}
310310
flags ^= ZIP_FL_OPEN_FILE_NOW;
311311
zs = zip_source_filep(obj->za, fd, offset_start, offset_len);
312+
if (!zs) {
313+
fclose(fd);
314+
return FAILURE;
315+
}
312316
} else {
313317
zs = zip_source_file(obj->za, resolved_path, offset_start, offset_len);
314-
}
315-
if (!zs) {
316-
return FAILURE;
318+
if (!zs) {
319+
return FAILURE;
320+
}
317321
}
318322
/* Replace */
319323
if (replace >= 0) {
@@ -797,7 +801,10 @@ int php_zip_pcre(zend_string *regexp, char *path, int path_len, zval *return_val
797801
if ((path_len + namelist_len + 1) >= MAXPATHLEN) {
798802
php_error_docref(NULL, E_WARNING, "add_path string too long (max: %u, %zu given)",
799803
MAXPATHLEN - 1, (path_len + namelist_len + 1));
800-
zend_string_release_ex(namelist[i], false);
804+
/* The loop isn't continued, so all remaining file names must get freed. */
805+
for (; i < files_cnt; i++) {
806+
zend_string_release_ex(namelist[i], false);
807+
}
801808
break;
802809
}
803810

@@ -2861,6 +2868,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
28612868
buffer = zend_string_safe_alloc(1, len, 0, false);
28622869
zip_int64_t n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
28632870
if (n < 1) {
2871+
zip_fclose(zf);
28642872
zend_string_efree(buffer);
28652873
RETURN_EMPTY_STRING();
28662874
}

0 commit comments

Comments
 (0)