Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, const char *lc_ha
if (str_len > ZSTR_LEN(lc_needle)) {
new_str = zend_string_safe_falloc(count, str_len - ZSTR_LEN(lc_needle), ZSTR_LEN(haystack), 0, /* fallible */ true);
if (UNEXPECTED(!new_str)) {
zend_string_release_ex(lc_needle, 0);
return NULL;
}
} else {
Expand Down
23 changes: 23 additions & 0 deletions ext/standard/tests/strings/str_ireplace_oom.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
str_ireplace() releases lowercased needle on OOM
--SKIPIF--
<?php
if (getenv('USE_ZEND_ALLOC') === '0') die('skip requires ZendMM');
?>
--INI--
memory_limit=4M
--FILE--
<?php
$base = memory_get_usage();
register_shutdown_function(function () use ($base) {
var_dump(memory_get_usage() - $base < 100000);
});
function trigger(): void {
$needle = str_repeat('A', 500000);
str_ireplace($needle, str_repeat('b', 1000000), str_repeat('a', 1000000));
}
trigger();
?>
--EXPECTF--
Fatal error: Allowed memory size of 4194304 bytes exhausted %S(tried to allocate %d bytes) in %s on line %d
bool(true)
Loading