Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Bug #80972: Memory exhaustion on invalid string offset
Closes GH-6890
- Loading branch information
Showing
6 changed files
with
54 additions
and
7 deletions.
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
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,41 @@ | ||
--TEST-- | ||
Bug #80972: Memory exhaustion on invalid string offset | ||
--FILE-- | ||
<?php | ||
|
||
function exceptions_error_handler($severity, $message, $filename, $lineno) { | ||
if (error_reporting() & $severity) { | ||
throw new ErrorException($message, 0, $severity, $filename, $lineno); | ||
} | ||
} | ||
set_error_handler('exceptions_error_handler'); | ||
|
||
$float = 10e120; | ||
$string_float = (string) $float; | ||
|
||
$string = 'Here is some text for good measure'; | ||
|
||
try { | ||
echo 'Float casted to string compile', \PHP_EOL; | ||
$string[(string) 10e120] = 'E'; | ||
var_dump($string); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
|
||
/* This same bug also permits to modify the first byte of a string even if | ||
* the offset is invalid */ | ||
try { | ||
/* This must not affect the string value */ | ||
$string["wrong"] = "f"; | ||
} catch (\Throwable $e) { | ||
echo $e->getMessage() . \PHP_EOL; | ||
} | ||
var_dump($string); | ||
|
||
?> | ||
--EXPECT-- | ||
Float casted to string compile | ||
Cannot access offset of type string on string | ||
Cannot access offset of type string on string | ||
string(34) "Here is some text for good measure" |
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