Bug #78612 [Ver->Csd]: strtr leaks memory when integer keys are used and the subject string shorter
Edit report at https://bugs.php.net/bug.php?id=78612&edit=1
ID: 78612
Updated by: nikic@php.net
Reported by: itsoft3g at gmail dot com
Summary: strtr leaks memory when integer keys are used and
the subject string shorter
-Status: Verified
+Status: Closed
Type: Bug
Package: Strings related
Operating System: Ubuntu 18.04.2 LTS
PHP Version: 7.3.10
Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6fcde56b0370125c32e6a7d198aff2afd01c35dc
Log: Fixed bug #78612
Previous Comments:
------------------------------------------------------------------------
[2019-09-30 12:27:08] itsoft3g at gmail dot com
Description:
------------
Passing 2nd argument as an array to strtr() - replace substrings
Here array keys are integers.
Say an interger (7111222333000001) is the find item, consider it as string its length is 16.
Say the subject is Hello which length is 5.
In this case, strtr leaks memory.
However, when the subject is longer than the find item, there is no memory leak.
Also when the find is string there too no memory leak.
Test script:
---------------
$find_replace = array();
$_a = 7111222333000001;//find - consider as string it's length is 16
$_b = 5000001;
for($j=0;$j<10;$j++){
$find_replace[$_a + $j] = $_b + $j;
}
function test_strtr($subject, $find_replace){
$memory_before = memory_get_usage();
for($i=0;$i<50000;$i++){
strtr($subject, $find_replace);
}
echo round( (memory_get_usage() - $memory_before) /(1024*1024), 4 ).' MB ';
}
test_strtr('Hello', $find_replace);//subject is shorter then find(length 5), memory leaks
test_strtr('Lorem ipsum dolor', $find_replace);//subject is lengthier then find(length
17), no memory leak
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78612&edit=1
Thread (3 messages)