Skip to content

Commit e9d5169

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Prevent double-free of Phar ZIP stream
2 parents 6fc0f8e + b7689db commit e9d5169

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

ext/phar/tests/zip/require_hash.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ try {
4545
@unlink(__DIR__ . '/require_hash.zip');
4646
?>
4747
--EXPECTF--
48-
zip-based phar "%srequire_hash.phar.zip" does not have a signature
48+
phar error: signature is missing in zip-based phar "%srequire_hash.phar.zip"
4949
bool(false)
5050
array(2) {
5151
["hash"]=>

ext/phar/zip.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,6 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
665665
zend_hash_str_add_mem(&mydata->manifest, entry.filename, entry.filename_len, (void *)&entry, sizeof(phar_entry_info));
666666
}
667667

668-
mydata->fp = fp;
669-
670668
if (zend_hash_str_exists(&(mydata->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1)) {
671669
mydata->is_data = 0;
672670
} else {
@@ -675,14 +673,11 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
675673

676674
/* ensure signature set */
677675
if (!mydata->is_data && PHAR_G(require_hash) && !mydata->signature) {
678-
php_stream_close(fp);
679-
phar_destroy_phar_data(mydata);
680-
if (error) {
681-
spprintf(error, 0, "zip-based phar \"%s\" does not have a signature", fname);
682-
}
683-
return FAILURE;
676+
PHAR_ZIP_FAIL("signature is missing");
684677
}
685678

679+
mydata->fp = fp;
680+
686681
zend_hash_str_add_ptr(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len, mydata);
687682

688683
if (actual_alias) {

0 commit comments

Comments
 (0)