📄 Viewing: bug80972.phpt

--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 (\Throwable $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
Illegal string offset '1.0E+121'
Illegal string offset 'wrong'
string(34) "Here is some text for good measure"

🌑 DarkStealth — WP Plugin Edition

Directory: /usr/src/php-7.4.23/Zend/tests