|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78272 calling preg_match() before pcntl_fork() will freeze child process
Submitted: 2019-07-10 15:32 UTC Modified: 2019-07-12 09:54 UTC
From: Assigned:
Status: Open Package: PCRE related
PHP Version: 7.3.7 OS: OSX
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-07-10 15:32 UTC]
When preg_match (or another preg_*function) has been called before pcntl_fork(), and then, called again in the child process, the child process stops at the preg_match, and just hangs. 

No error, no crash. 

This was tested on OSX, and it couldn't be replicated on Debian. This may be specific to OSX.

It is reproductible with PHP 7.3.7. It works on 7.2, 7.1.

It may be related to 

Test script:
// Uncomment the following to freeze child process
//        preg_match('/abc/', 'abcde', $r);

        $pid = pcntl_fork();
        if ($pid === 0) {
            print "Child start\n";
            preg_match('/abc/', 'abcde', $r);
            print "End child\n";
        } else {
            print "Main start\n";
            print "End Main\n";

Expected result:
Main start
Child start
    [0] => abc
End child
End Main

Actual result:
Main start
Child start
End Main


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-10 15:37 UTC]
Is it possible for you test whether this works on 7.4 (has an updated PCRE2)?
 [2019-07-10 15:37 UTC]
And also whether it works if you set pcre.jit=0.
 [2019-07-10 16:03 UTC]
pcre.jit=0 fixes the problem, both with PHP 7.3 and 7.4.

pcre.jit=1 behave the same with php 7.3 and 7.4.
 [2019-07-11 10:59 UTC]
I was not able to reproduce this issue on 7.4 on Darwin 16.0.0. I tried both NTS and ZTS builds.
 [2019-07-12 09:54 UTC]
Here is my build sequence : 

git pull
git checkout PHP-7.4; git pull
make clean
./buildconf --force
env YACC=`brew --prefix bison`/bin/bison ./configure \
    --prefix="/usr/local/opt/php74" \
    --with-config-file-path="/usr/local/etc/php71" \
    --with-config-file-scan-dir=/usr/local/etc/phpng/conf.d \
    --enable-mbstring \
    --enable-tokenizer \
    --enable-mbstring \
    --with-sqlite3=/usr/local/Cellar/sqlite/3.28.0 \
    --with-sodium=/usr/local/opt/libsodium \
    --enable-json \
    --enable-pcntl \
gmake -j`sysctl -n hw.logicalcpu_max`
gmake test

I have the last OSX patches : 
      System Version: macOS 10.14.5 (18F132)
      Kernel Version: Darwin 18.6.0
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Aug 21 00:01:34 2019 UTC