diff --git a/ext/phar/tests/zip/gh25089.phpt b/ext/phar/tests/zip/gh25089.phpt new file mode 100644 index 000000000000..ec68c035f0c4 --- /dev/null +++ b/ext/phar/tests/zip/gh25089.phpt @@ -0,0 +1,35 @@ +--TEST-- +GH-25089 (Heap buffer over-read via crafted alias size in zip-based phar) +--EXTENSIONS-- +phar +zlib +--FILE-- +getAlias()); +?> +--CLEAN-- + +--EXPECT-- +string(4) "ABCD" diff --git a/ext/phar/zip.c b/ext/phar/zip.c index f051c35a09a7..c1230cb78079 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -648,7 +648,6 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia fp->readpos = 0; /* the above lines should be for php < 5.2.6 after 5.3 filters are fixed */ - mydata->alias_len = entry.uncompressed_filesize; if (entry.flags & PHAR_ENT_COMPRESSED_GZ) { filter = php_stream_filter_create("zlib.inflate", NULL, php_stream_is_persistent(fp)); @@ -735,6 +734,8 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia } } + mydata->alias_len = entry.uncompressed_filesize; + /* return to central directory parsing */ php_stream_seek(fp, restore_pos, SEEK_SET); }