|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78612 strtr leaks memory when integer keys are used and the subject string shorter
Submitted: 2019-09-30 12:27 UTC Modified: 2019-09-30 13:03 UTC
From: itsoft3g at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Strings related
PHP Version: 7.3.10 OS: Ubuntu 18.04.2 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: itsoft3g at gmail dot com
New email:
PHP Version: OS:


 [2019-09-30 12:27 UTC] itsoft3g at gmail dot com
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;

	$find_replace[$_a + $j] = $_b + $j;

function test_strtr($subject, $find_replace){
	$memory_before = memory_get_usage();
		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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-30 12:59 UTC]
-Status: Open +Status: Verified
 [2019-09-30 13:03 UTC]
-Assigned To: +Assigned To: nikic
 [2019-09-30 13:07 UTC]
Automatic comment on behalf of
Log: Fixed bug #78612
 [2019-09-30 13:07 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 13:01:31 2024 UTC