Skip to content

Commit 910aeaa

Browse files
committed
Add missing filter cleanups on phar failure
Closes GH-18609.
1 parent 8e2c2be commit 910aeaa

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.23
44

5+
- Phar:
6+
. Add missing filter cleanups on phar failure. (nielsdos)
57

68
05 Jun 2025, PHP 8.3.22
79

ext/phar/phar.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17041704
php_stream_filter_append(&temp->writefilters, filter);
17051705

17061706
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1707+
php_stream_filter_remove(filter, 1);
17071708
if (err) {
17081709
php_stream_close(temp);
17091710
MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\", ext/zlib is buggy in PHP versions older than 5.2.6")
@@ -1750,6 +1751,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
17501751
php_stream_filter_append(&temp->writefilters, filter);
17511752

17521753
if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
1754+
php_stream_filter_remove(filter, 1);
17531755
php_stream_close(temp);
17541756
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file")
17551757
}
@@ -2833,6 +2835,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
28332835
}
28342836
entry->cfp = shared_cfp;
28352837
if (!entry->cfp) {
2838+
php_stream_filter_free(filter);
28362839
if (error) {
28372840
spprintf(error, 0, "unable to create temporary file");
28382841
}
@@ -2847,6 +2850,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
28472850
entry->header_offset = php_stream_tell(entry->cfp);
28482851
php_stream_flush(file);
28492852
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
2853+
php_stream_filter_free(filter);
28502854
if (closeoldfile) {
28512855
php_stream_close(oldfile);
28522856
}
@@ -2858,6 +2862,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
28582862
}
28592863
php_stream_filter_append((&entry->cfp->writefilters), filter);
28602864
if (SUCCESS != php_stream_copy_to_stream_ex(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
2865+
php_stream_filter_remove(filter, 1);
28612866
if (closeoldfile) {
28622867
php_stream_close(oldfile);
28632868
}

ext/phar/zip.c

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

644644
if (!entry.uncompressed_filesize || !actual_alias) {
645+
php_stream_filter_remove(filter, 1);
645646
pefree(entry.filename, entry.is_persistent);
646647
PHAR_ZIP_FAIL("unable to read in alias, truncated");
647648
}
@@ -674,6 +675,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
674675
}
675676

676677
if (!entry.uncompressed_filesize || !actual_alias) {
678+
php_stream_filter_remove(filter, 1);
677679
pefree(entry.filename, entry.is_persistent);
678680
PHAR_ZIP_FAIL("unable to read in alias, truncated");
679681
}
@@ -968,20 +970,23 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{
968970
entry->cfp = php_stream_fopen_tmpfile();
969971

970972
if (!entry->cfp) {
973+
php_stream_filter_free(filter);
971974
spprintf(p->error, 0, "unable to create temporary file for file \"%s\" while creating zip-based phar \"%s\"", entry->filename, entry->phar->fname);
972975
return ZEND_HASH_APPLY_STOP;
973976
}
974977

975978
php_stream_flush(efp);
976979

977980
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
981+
php_stream_filter_free(filter);
978982
spprintf(p->error, 0, "unable to seek to start of file \"%s\" to zip-based phar \"%s\"", entry->filename, entry->phar->fname);
979983
return ZEND_HASH_APPLY_STOP;
980984
}
981985

982986
php_stream_filter_append((&entry->cfp->writefilters), filter);
983987

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

0 commit comments

Comments
 (0)