Skip to content

Commit 752b53c

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2 parents 75426c5 + c4333a7 commit 752b53c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ext/phar/phar.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,18 +1647,19 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16471647
if (!PHAR_G(has_zlib)) {
16481648
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\" to temporary file, enable zlib extension in php.ini")
16491649
}
1650+
1651+
/* entire file is gzip-compressed, uncompress to temporary file */
1652+
if (!(temp = php_stream_fopen_tmpfile())) {
1653+
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1654+
}
1655+
16501656
array_init(&filterparams);
16511657
/* this is defined in zlib's zconf.h */
16521658
#ifndef MAX_WBITS
16531659
#define MAX_WBITS 15
16541660
#endif
16551661
add_assoc_long_ex(&filterparams, "window", sizeof("window") - 1, MAX_WBITS + 32);
16561662

1657-
/* entire file is gzip-compressed, uncompress to temporary file */
1658-
if (!(temp = php_stream_fopen_tmpfile())) {
1659-
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1660-
}
1661-
16621663
php_stream_rewind(fp);
16631664
filter = php_stream_filter_create("zlib.inflate", &filterparams, php_stream_is_persistent(fp));
16641665

0 commit comments

Comments
 (0)