Skip to content

Commit ed30969

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Add missing filter cleanups on phar failure
2 parents 9da2c24 + f9785c2 commit ed30969

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ext/phar/phar.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17141714
php_stream_filter_append(&temp->writefilters, filter);
17151715

17161716
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1717+
php_stream_filter_remove(filter, 1);
17171718
if (err) {
17181719
php_stream_close(temp);
17191720
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\", ext/zlib is buggy in PHP versions older than 5.2.6")
@@ -1760,6 +1761,7 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17601761
php_stream_filter_append(&temp->writefilters, filter);
17611762

17621763
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1764+
php_stream_filter_remove(filter, 1);
17631765
php_stream_close(temp);
17641766
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file")
17651767
}
@@ -2804,6 +2806,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
28042806
}
28052807
entry->cfp = shared_cfp;
28062808
if (!entry->cfp) {
2809+
php_stream_filter_free(filter);
28072810
if (error) {
28082811
spprintf(error, 0, "unable to create temporary file");
28092812
}
@@ -2818,6 +2821,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
28182821
entry->header_offset = php_stream_tell(entry->cfp);
28192822
php_stream_flush(file);
28202823
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
2824+
php_stream_filter_free(filter);
28212825
if (must_close_old_file) {
28222826
php_stream_close(oldfile);
28232827
}
@@ -2829,6 +2833,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
28292833
}
28302834
php_stream_filter_append((&entry->cfp->writefilters), filter);
28312835
if (SUCCESS != php_stream_copy_to_stream_ex(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
2836+
php_stream_filter_remove(filter, 1);
28322837
if (must_close_old_file) {
28332838
php_stream_close(oldfile);
28342839
}

ext/phar/zip.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
675675
}
676676

677677
if (!entry.uncompressed_filesize || !actual_alias) {
678+
php_stream_filter_remove(filter, 1);
678679
zend_string_release_ex(entry.filename, entry.is_persistent);
679680
PHAR_ZIP_FAIL("unable to read in alias, truncated");
680681
}
@@ -707,6 +708,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
707708
}
708709

709710
if (!entry.uncompressed_filesize || !actual_alias) {
711+
php_stream_filter_remove(filter, 1);
710712
zend_string_release_ex(entry.filename, entry.is_persistent);
711713
PHAR_ZIP_FAIL("unable to read in alias, truncated");
712714
}
@@ -1000,20 +1002,23 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{
10001002
entry->cfp = php_stream_fopen_tmpfile();
10011003

10021004
if (!entry->cfp) {
1005+
php_stream_filter_free(filter);
10031006
spprintf(p->error, 0, "unable to create temporary file for file \"%s\" while creating zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname);
10041007
return ZEND_HASH_APPLY_STOP;
10051008
}
10061009

10071010
php_stream_flush(efp);
10081011

10091012
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
1013+
php_stream_filter_free(filter);
10101014
spprintf(p->error, 0, "unable to seek to start of file \"%s\" to zip-based phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname);
10111015
return ZEND_HASH_APPLY_STOP;
10121016
}
10131017

10141018
php_stream_filter_append((&entry->cfp->writefilters), filter);
10151019

10161020
if (SUCCESS != php_stream_copy_to_stream_ex(efp, entry->cfp, entry->uncompressed_filesize, NULL)) {
1021+
php_stream_filter_remove(filter, 1);
10171022
spprintf(p->error, 0, "unable to copy compressed file contents of file \"%s\" while creating new phar \"%s\"", ZSTR_VAL(entry->filename), entry->phar->fname);
10181023
return ZEND_HASH_APPLY_STOP;
10191024
}

0 commit comments

Comments
 (0)