Skip to content

Commit c4cba94

Browse files
committed
Fix Bug #80972: Memory exhaustion on invalid string offset
1 parent 3c64805 commit c4cba94

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Zend/tests/bug80972.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #80972: Memory exhaustion on invalid string offset
3+
--FILE--
4+
<?php
5+
6+
$float = 10e120;
7+
$string_float = (string) $float;
8+
9+
$string = 'Here is some text for good measure';
10+
11+
try {
12+
echo 'Float casted to string compile', \PHP_EOL;
13+
$string[(string) 10e120] = 'E';
14+
var_dump($string);
15+
} catch (\TypeError $e) {
16+
echo $e->getMessage(), \PHP_EOL;
17+
}
18+
19+
?>
20+
--EXPECT--
21+
Float casted to string compile
22+
Cannot access offset of type string on string

Zend/zend_execute.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,14 @@ static zend_never_inline void zend_assign_to_string_offset(zval *str, zval *dim,
15251525
zend_long offset;
15261526

15271527
offset = zend_check_string_offset(dim, BP_VAR_W EXECUTE_DATA_CC);
1528+
/* Illegal offset assignment */
1529+
if (UNEXPECTED(EG(exception) != NULL)) {
1530+
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
1531+
ZVAL_UNDEF(EX_VAR(opline->result.var));
1532+
}
1533+
return;
1534+
}
1535+
15281536
if (offset < -(zend_long)Z_STRLEN_P(str)) {
15291537
/* Error on negative offset */
15301538
zend_error(E_WARNING, "Illegal string offset " ZEND_LONG_FMT, offset);

0 commit comments

Comments
 (0)