Skip to content

Add missing filter cleanups on phar failure #18609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@ static int phar_open_from_fp(php_stream* fp, char *fname, size_t fname_len, char
php_stream_filter_append(&temp->writefilters, filter);

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

if (SUCCESS != php_stream_copy_to_stream_ex(fp, temp, PHP_STREAM_COPY_ALL, NULL)) {
php_stream_filter_remove(filter, 1);
php_stream_close(temp);
MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file")
}
Expand Down Expand Up @@ -2833,6 +2835,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
}
entry->cfp = shared_cfp;
if (!entry->cfp) {
php_stream_filter_free(filter);
if (error) {
spprintf(error, 0, "unable to create temporary file");
}
Expand All @@ -2847,6 +2850,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
entry->header_offset = php_stream_tell(entry->cfp);
php_stream_flush(file);
if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0)) {
php_stream_filter_free(filter);
if (closeoldfile) {
php_stream_close(oldfile);
}
Expand All @@ -2858,6 +2862,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
}
php_stream_filter_append((&entry->cfp->writefilters), filter);
if (SUCCESS != php_stream_copy_to_stream_ex(file, entry->cfp, entry->uncompressed_filesize, NULL)) {
php_stream_filter_remove(filter, 1);
if (closeoldfile) {
php_stream_close(oldfile);
}
Expand Down
5 changes: 5 additions & 0 deletions ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
}

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

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

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

php_stream_flush(efp);

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

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

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