|  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-09-18 08:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned:
Status: Closed Package: PCRE related
PHP Version: 7.3.7 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [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
 [2019-09-18 08:25 UTC]
-Status: Open +Status: Verified
 [2019-09-18 08:25 UTC]
Reproduced on CI.
 [2019-09-18 08:45 UTC]
Automatic comment on behalf of
Log: Fixed bug #78272
 [2019-09-18 08:45 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 06:03:36 2021 UTC