Skip to content

Commit 83cf4aa

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #73809: Phar Zip parse crash - mmap fail
2 parents 44475e7 + c283f53 commit 83cf4aa

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PHP NEWS
3232
. Fixed bug #80368 (OpenSSL extension fails to build against LibreSSL due to
3333
lack of OCB support). (Nikita)
3434

35+
- Phar:
36+
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)
37+
3538
- Phpdbg:
3639
. Fixed bug #76813 (Access violation near NULL on source operand). (cmb)
3740

ext/phar/tests/bug73809.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #73809 (Phar Zip parse crash - mmap fail)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('phar')) die('skip phar extension not available');
6+
if (!extension_loaded('zip')) die('skip zip extension not available');
7+
?>
8+
--FILE--
9+
<?php
10+
// create the ZIP to be tested
11+
$zip = new ZipArchive;
12+
$zip->open(__DIR__ . '/73809.zip', ZipArchive::CREATE);
13+
$zip->addFromString('73809.txt', 'yada yada');
14+
$zip->addFromString('.phar/signature.bin', str_repeat('*', 64 * 1024 + 1));
15+
$zip->setCompressionName('.phar/signature.bin', ZipArchive::CM_STORE);
16+
var_dump($zip->close());
17+
18+
try {
19+
$phar = new PharData(__DIR__ . '/73809.zip');
20+
} catch (Exception $ex) {
21+
echo $ex->getMessage(), PHP_EOL;
22+
}
23+
?>
24+
--CLEAN--
25+
<?php
26+
@unlink(__DIR__ . '/73809.zip');
27+
?>
28+
--EXPECTF--
29+
bool(true)
30+
phar error: signatures larger than 64 KiB are not supported in zip-based phar "%s"

ext/phar/zip.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,13 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
401401
char *sig;
402402
size_t sig_len;
403403

404-
php_stream_tell(fp);
405404
pefree(entry.filename, entry.is_persistent);
405+
406+
if (entry.uncompressed_filesize > 0x10000) {
407+
PHAR_ZIP_FAIL("signatures larger than 64 KiB are not supported");
408+
}
409+
410+
php_stream_tell(fp);
406411
sigfile = php_stream_fopen_tmpfile();
407412
if (!sigfile) {
408413
PHAR_ZIP_FAIL("couldn't open temporary file");

0 commit comments

Comments
 (0)