Skip to content

Commit 416386a

Browse files
committed
Fix memory leak in phar_parse_zipfile() error handling
Closes phpGH-20134.
1 parent efa1faf commit 416386a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PHP NEWS
1818
- Phar:
1919
. Fix memory leak of argument in webPhar. (nielsdos)
2020
. Fix memory leak when setAlias() fails. (nielsdos)
21+
. Fix memory leak in phar_parse_zipfile() error handling. (nielsdos)
2122

2223
- Random:
2324
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)

ext/phar/zip.c

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

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

677-
if (!entry.uncompressed_filesize || !actual_alias) {
678+
if (!entry.uncompressed_filesize) {
679+
efree(actual_alias);
678680
php_stream_filter_remove(filter, 1);
679681
pefree(entry.filename, entry.is_persistent);
680682
PHAR_ZIP_FAIL("unable to read in alias, truncated");
@@ -697,7 +699,8 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
697699
}
698700
}
699701

700-
if (!entry.uncompressed_filesize || !actual_alias) {
702+
if (!entry.uncompressed_filesize) {
703+
efree(actual_alias);
701704
pefree(entry.filename, entry.is_persistent);
702705
PHAR_ZIP_FAIL("unable to read in alias, truncated");
703706
}

0 commit comments

Comments
 (0)