Skip to content

Fix #73809: Phar Zip parse crash - mmap fail #6474

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
30 changes: 30 additions & 0 deletions ext/phar/tests/bug73809.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Bug #73809 (Phar Zip parse crash - mmap fail)
--SKIPIF--
<?php
if (!extension_loaded('phar')) die('skip phar extension not available');
if (!extension_loaded('zip')) die('skip zip extension not available');
?>
--FILE--
<?php
// create the ZIP to be tested
$zip = new ZipArchive;
$zip->open(__DIR__ . '/73809.zip', ZipArchive::CREATE);
$zip->addFromString('73809.txt', 'yada yada');
$zip->addFromString('.phar/signature.bin', str_repeat('*', 64 * 1024 + 1));
$zip->setCompressionName('.phar/signature.bin', ZipArchive::CM_STORE);
var_dump($zip->close());

try {
$phar = new PharData(__DIR__ . '/73809.zip');
} catch (Exception $ex) {
echo $ex->getMessage(), PHP_EOL;
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/73809.zip');
?>
--EXPECTF--
bool(true)
phar error: signatures larger than 64 KiB are not supported in zip-based phar "%s"
7 changes: 6 additions & 1 deletion ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,13 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
char *sig;
size_t sig_len;

php_stream_tell(fp);
pefree(entry.filename, entry.is_persistent);

if (entry.uncompressed_filesize > 0x10000) {
PHAR_ZIP_FAIL("signatures larger than 64 KiB are not supported");
}

php_stream_tell(fp);
sigfile = php_stream_fopen_tmpfile();
if (!sigfile) {
PHAR_ZIP_FAIL("couldn't open temporary file");
Expand Down