0

I have a legacy text filter, which uses preg_replace_callback for parsing. However, when the parsed text is too complex, the code dies with no error message given, except for this PHP log entry WARNING: [pool www] child ... exited on signal 11.

To illustrate the problem, run the following code with values 10 and 20 in the $rows variable:

<?php

function my_callback(&$matches) {
    return $matches[0];
}

$regex = '#^\{\|(.*?)(?:^\|\+(.*?))?(^(?:((?R))|.)*?)^\|}#msi';

$columns = '';
$rows = 10; // 20 causes WSOD with no error given

for ($i=0; $i<20; $i++) {
  $columns .= "| style=\"width:6em\" | $i\n";
}
$body = "{|\n" . implode("|-\n", array_fill(0, $rows, $columns)) . "\n|}";

print preg_replace_callback($regex, 'my_callback', $body);

How do I increase the correcponding resource limit (assuming there is some) the code is hitting? Any help highly appreciated!

Michal Gow
  • 356
  • 1
  • 4
  • 12

1 Answers1

0

After deep digging it turned out, that this is a variant of an insufficient size of PCRE stack. To debug, it was required to run the program on the cli PHP, when it was possible to use the preg_last_error() on its last line, to obtain the error message (6 in this case).

The solution to this is either to recompile PCRE to use bigger stack, or to rewrite the REGEX to use less memory (effectively to give up the recursion).

Michal Gow
  • 356
  • 1
  • 4
  • 12