Bug #69741 [Opn]: preg_replace memory fail

From: Date: Thu, 04 Jun 2015 08:03:57 +0000
Subject: Bug #69741 [Opn]: preg_replace memory fail
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193110@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69741&edit=1 ID: 69741 User updated by: informatica at ortopediaplus dot com Reported by: informatica at ortopediaplus dot com Summary: preg_replace memory fail Status: Open Type: Bug Package: PCRE related Operating System: Linux 2.6.32-504.8.1.el6.x86_64 PHP Version: 5.6.9 Block user comment: N Private report: N New Comment: The error persists. In the documentation, for meta-characters: . match any character except newline (by default) My variable $content has newline (\n). Fail with \n "/<!--TAG_INI-->(.|\n)*?<!--TAG_END-->/s" Previous Comments: ------------------------------------------------------------------------ [2015-06-04 01:48:44] cmb@php.net See <http://3v4l.org/ICria>. The segfault occurs for PHP 4 and 5, but has been resolved in current master (the upcoming PHP 7). However, I wonder why you don't use the following pattern: "/<!--TAG_INI-->.*?<!--TAG_END-->/s" That seems to be more intuitive, and works fine even with very old PHP versions, see <http://3v4l.org/UUFM6>. Apparently, there has been a bug introduced with PHP 5.2.0 and resolved with PHP 5.3.7, though. ------------------------------------------------------------------------ [2015-06-02 08:18:06] informatica at ortopediaplus dot com With memory fail hasn't pcre.backtrack_limit and pcre.recursion_limit. If I use pcre.backtrack_limit or pcre.recursion_limit with any value (1, 100, 1000, 10000), then preg_replace return NULL if match or return $content if not match. I'm absolutely sure with the string "<!--TAG_END-->". ------------------------------------------------------------------------ [2015-06-01 19:52:35] requinix@php.net What are your pcre.* INI settings? And are you absolutely sure the string does contain "<!--TAG_END-->"? ------------------------------------------------------------------------ [2015-06-01 16:18:39] informatica at ortopediaplus dot com Description: ------------ Segmentation fault use preg_replace Test script: --------------- $pattern = "/<!--TAG_INI-->(.|\n)*?<!--TAG_END-->/"; There are 100000 characters between <!--TAG_INI--> and <!--TAG_END--> in $content $content = preg_replace($pattern, 'foo', $content); SEGMENTATION FAULT!!! Expected result: ---------------- Replace all text between <!--TAG_INI--> and <!--TAG_END--> to 'foo' Actual result: -------------- SEGMENTATION FAULT. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69741&edit=1

« previous php.bugs (#193110) next »