Skip to content

Commit 913327d

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: phar: Fix memory leak when opening temp file fails while trying to open gzip-compressed archive
2 parents 40efac0 + ce0df1a commit 913327d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ PHP NEWS
6161
of type size_t. (Girgias)
6262
. Fix memory leak when openssl polyfill returns garbage. (nielsdos)
6363
. Fix file descriptor leak in phar_zip_flush() on failure. (nielsdos)
64+
. Fix memory leak when opening temp file fails while trying to open
65+
gzip-compressed archive. (nielsdos)
6466

6567
- Random:
6668
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)

ext/phar/phar.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,18 +1674,19 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16741674
if (!PHAR_G(has_zlib)) {
16751675
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\" to temporary file, enable zlib extension in php.ini")
16761676
}
1677+
1678+
/* entire file is gzip-compressed, uncompress to temporary file */
1679+
if (!(temp = php_stream_fopen_tmpfile())) {
1680+
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1681+
}
1682+
16771683
array_init(&filterparams);
16781684
/* this is defined in zlib's zconf.h */
16791685
#ifndef MAX_WBITS
16801686
#define MAX_WBITS 15
16811687
#endif
16821688
add_assoc_long_ex(&filterparams, "window", sizeof("window") - 1, MAX_WBITS + 32);
16831689

1684-
/* entire file is gzip-compressed, uncompress to temporary file */
1685-
if (!(temp = php_stream_fopen_tmpfile())) {
1686-
MAPPHAR_ALLOC_FAIL("unable to create temporary file for decompression of gzipped phar archive \"%s\"")
1687-
}
1688-
16891690
php_stream_rewind(fp);
16901691
filter = php_stream_filter_create("zlib.inflate", &filterparams, php_stream_is_persistent(fp));
16911692

0 commit comments

Comments
 (0)