-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #73809: Phar Zip parse crash - mmap fail
Phar signatures practically are of limited size; for the MD5 and SHA hashes the size is fixed (at most 64 bytes for SHA512); for OpenSSL public keys there is no size limit in theory, but "64 KiB ought to be good enough for anybody". So we check for that limit, to avoid fatal errors due to out of memory conditions. Since it is neither possible to have the signature compressed in the ZIP archive, nor is it possible to manually add a signature via Phar, we use ZipArchive to create a suitable archive for the test on the fly. Closes GH-6474.
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters