php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60927 Recursive functions for preg_replace_callback causes SEGFAULT
Submitted: 2012-01-29 19:33 UTC Modified: 2012-01-29 20:39 UTC
From: jimmy at axenhus dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.9 OS: Ubuntu 11.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jimmy at axenhus dot com
New email:
PHP Version: OS:

 

 [2012-01-29 19:33 UTC] jimmy at axenhus dot com
Description:
------------
Using recursive functions for preg_replace_callback that never ends PHP will exit with a SEGFAULT (unexpected signal 11) due to a function stack overflow.

It's expected that it should never end and therefore PHP should abort the execution. However PHP should output a helpful error message rather than just aborting it. Depending on your code this could be a major issue to debug. (I was using Drupal and it look me hours to find the source.)

Test script:
---------------
<?php

function a() {
  b();
}
function b() {
  a();
}

preg_replace_callback("/0/s", 'a', "0");
echo "We made it my friend!";


Expected result:
----------------
Some sort of error message that the callback stack limit has been reached.

Actual result:
--------------
A 500 Internal Server error (Apache with mod_fcgid) and a SEGFAULT in the error log.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-29 19:47 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Recursion ends in a stack overflow. A stack overflow makes the operating system kill the process.
 [2012-01-29 19:47 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2012-01-29 20:39 UTC] johannes@php.net
.
 [2012-01-29 20:39 UTC] johannes@php.net
-Status: Bogus +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 14:01:34 2025 UTC