Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #77432: Segmentation fault on including phar file
phar_get_pharfp() can return NULL. In this case this is because the stream gets closed by the include code in the engine. However, the phar entry is still cached, so when the next include happens the engine tries to read from a closed (and nullified) stream. Use the same fix as in phar_open_entry_fp(): take into account that the phar_get_pharfp() can return NULL and in that case reopen the phar archive. Closes GH-13056.
- Loading branch information
Showing
3 changed files
with
61 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
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,46 @@ | ||
--TEST-- | ||
Bug #77432 (Segmentation fault on including phar file) | ||
--EXTENSIONS-- | ||
phar | ||
--INI-- | ||
phar.readonly=0 | ||
--FILE-- | ||
<?php | ||
|
||
$filename = __DIR__ . '/bug77432.phar'; | ||
|
||
$phar = new Phar($filename); | ||
$phar->startBuffering(); | ||
$phar->addFromString('test.txt', 'text'); | ||
$phar->setStub('<?php echo "hello world\n"; __HALT_COMPILER(); ?>'); | ||
$phar->stopBuffering(); | ||
unset($phar); | ||
|
||
echo "--- Include 1 ---\n"; | ||
include("phar://" . $filename); | ||
echo "--- Include 2 ---\n"; | ||
// Note: will warn because the halting offset is redefined, but won't display the name because "zend_mangle_property_name" starts the name with \0 | ||
// However, this is just the easiest way to reproduce it, so go with this test. | ||
include("phar://" . $filename); | ||
echo "--- After unlink ---\n"; | ||
unlink($filename); | ||
// This will just fail, as it should, but it is here to test the reopen error-handling path. | ||
include("phar://" . $filename); | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__ . '/bug77432.phar'); | ||
?> | ||
--EXPECTF-- | ||
--- Include 1 --- | ||
hello world | ||
--- Include 2 --- | ||
|
||
Warning: Constant already defined in %s on line %d | ||
hello world | ||
--- After unlink --- | ||
|
||
Warning: include(%sbug77432.phar): Failed to open stream: phar error: could not reopen phar "%sbug77432.phar" in %s on line %d | ||
|
||
Warning: include(): Failed opening '%sbug77432.phar' for inclusion (include_path='.:') in %s on line %d |