[php-src] master: Merge branch 'PHP-8.0'

From: Date: Mon, 26 Apr 2021 12:23:12 +0000
Subject: [php-src] master: Merge branch 'PHP-8.0'
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-115824@lists.php.net to get a copy of this message
Author: George Peter Banyard (Girgias) Date: 2021-04-26T13:22:37+01:00 Commit: https://github.com/php/php-src/commit/7372a3e1174f5bfee1bff1be53e3c39f5c00c563 Raw diff: https://github.com/php/php-src/commit/7372a3e1174f5bfee1bff1be53e3c39f5c00c563.diff Merge branch 'PHP-8.0' * PHP-8.0: Fix Bug #80972: Memory exhaustion on invalid string offset Changed paths: A Zend/tests/bug80972.phpt M Zend/tests/bug31098.phpt M Zend/tests/bug53432.phpt M Zend/tests/indexing_001.phpt M Zend/zend_execute.c Diff: diff --git a/Zend/tests/bug31098.phpt b/Zend/tests/bug31098.phpt index 1cad1108c08d..862fc6fc46dc 100644 --- a/Zend/tests/bug31098.phpt +++ b/Zend/tests/bug31098.phpt @@ -35,11 +35,12 @@ try { } echo $simpleString["0"] === "B"?"ok\n":"bug\n"; try { + /* This must not affect the string value */ $simpleString["wrong"] = "f"; } catch (\TypeError $e) { echo $e->getMessage() . \PHP_EOL; } -echo $simpleString["0"] === "f"?"ok\n":"bug\n"; +echo $simpleString["0"] === "B"?"ok\n":"bug\n"; ?> --EXPECTF-- bool(false) diff --git a/Zend/tests/bug53432.phpt b/Zend/tests/bug53432.phpt index fb6b80857aa0..aa2a6015f51f 100644 --- a/Zend/tests/bug53432.phpt +++ b/Zend/tests/bug53432.phpt @@ -58,7 +58,7 @@ Warning: Illegal string offset -1 in %s on line %d NULL string(0) "" Cannot access offset of type string on string -string(1) "a" +string(0) "" Error: [] operator not supported for strings string(0) "" Error: Cannot use assign-op operators with string offsets diff --git a/Zend/tests/bug80972.phpt b/Zend/tests/bug80972.phpt new file mode 100644 index 000000000000..01d1a98952da --- /dev/null +++ b/Zend/tests/bug80972.phpt @@ -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" diff --git a/Zend/tests/indexing_001.phpt b/Zend/tests/indexing_001.phpt index c712b0980235..00f98237b595 100644 --- a/Zend/tests/indexing_001.phpt +++ b/Zend/tests/indexing_001.phpt @@ -52,7 +52,7 @@ foreach ($testvalues as $testvalue) { } ?> ---EXPECTF-- +--EXPECT-- *** Indexing - Testing value assignment with key *** array(1) { ["foo"]=> @@ -74,12 +74,8 @@ array(1) { int(1) } } - -Warning: Array to string conversion in %s on line %d Cannot access offset of type string on string string(0) "" - -Warning: Array to string conversion in %s on line %d Cannot access offset of type string on string string(1) " " Cannot use a scalar value as an array diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 889324e347c0..151eb4ecc59a 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1592,6 +1592,14 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim, zend_long offset; offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC); + /* Illegal offset assignment */ + if (UNEXPECTED(EG(exception) != NULL)) { + if (UNEXPECTED(RETURN_VALUE_USED(opline))) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return; + } + if (offset < -(zend_long)Z_STRLEN_P(str)) { /* Error on negative offset */ zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);

« previous php.cvs (#115824) next »