Skip to content

Commit 6fcde56

Browse files
committed
Fixed bug #78612
1 parent 45db6fa commit 6fcde56

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ PHP NEWS
1919
- Standard:
2020
. Fixed bug #76342 (file_get_contents waits twice specified timeout).
2121
(Thomas Calvet)
22+
. Fixed bug #78612 (strtr leaks memory when integer keys are used and the
23+
subject string shorter). (Nikita)
2224

2325
26 Sep 2019, PHP 7.2.23
2426

ext/standard/string.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
30273027
len = ZSTR_LEN(key_used);
30283028
if (UNEXPECTED(len > slen)) {
30293029
/* skip long patterns */
3030+
zend_string_release(key_used);
30303031
continue;
30313032
}
30323033
if (len > maxlen) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #78612 (strtr leaks memory when integer keys are used and the subject string shorter).
3+
--FILE--
4+
<?php
5+
6+
$find_replace = array();
7+
$_a = 7111222333000001;
8+
$_b = 5000001;
9+
10+
for ($j=0; $j<10; $j++) {
11+
$find_replace[$_a + $j] = $_b + $j;
12+
}
13+
14+
echo strtr('Hello', $find_replace), "\n";
15+
16+
?>
17+
--EXPECT--
18+
Hello

0 commit comments

Comments
 (0)