|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38728 preg_replace in UTF-mode memory leak
Submitted: 2006-09-05 21:41 UTC Modified: 2006-09-06 13:45 UTC
From: doktor at farlep dot net Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 4.4.4 OS: Linux Slackware 9.1.0
Private report: No CVE-ID: None
 [2006-09-05 21:41 UTC] doktor at farlep dot net
usage unicode character properties \pL and \Sm in function preg_replace give apache memory leak. (apache compilled with libphp4.a)
linux load average up to 98 

Reproduce code:
$patterns[] = "#\[url=([\pL]+?://[(\pL\Sm\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url3'];
$text = preg_replace($patterns, $replacements, $text);

Expected result:
replacing unicode characters in bbcode ( work fine with \w property, but in utf mode with values greater than 128 never match)

Actual result:
memory leak
load average: 98.3
fixed - not usage \pL and \Sm in preg_replace and restarting apache server


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-06 08:38 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2006-09-06 13:41 UTC] doktor at farlep dot net
I am sorry, but I don't write or attach script, beacose this code from forum phpBB (file includes/bbcode.php). This forum has very much lines of code ;)
I am only change property \w on \pL\Sm in 6 functions in this file and apache server memory leak. If I change properties back on \w and restart apache - all work fine.
I'm talk with phpBB-developers and they says what this bug in  php and recommended usage function mb_eregi_replace() instead of preg_replace()
ps: sorry for my bad english :(
 [2006-09-06 13:45 UTC]
We can't fix something we're unable to reproduce.
Please provide a short reproduce case. Until then -> bogus.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 13:01:28 2024 UTC