Bug #77260 [Opn]: preg_match_all(): JIT compilation failed: no more memory

From: Date: Mon, 10 Dec 2018 15:17:53 +0000
Subject: Bug #77260 [Opn]: preg_match_all(): JIT compilation failed: no more memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218367@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77260&edit=1

 ID:                 77260
 User updated by:    ettore at themecraft dot studio
 Reported by:        ettore at themecraft dot studio
 Summary:            preg_match_all(): JIT compilation failed: no more
                     memory
 Status:             Open
 Type:               Bug
 Package:            PCRE related
 Operating System:   macOS 10.13.6
 PHP Version:        7.3.0
 Block user comment: N
 Private report:     N

 New Comment:

Just tried with the latest commit on master (ad06f1aa2e). The error persists. If you need more
details on my system configuration, just ask.

I did not experience this issue on production servers running Debian and PHP 7.3 from sury.

Note and off-topic: I've run into some compilation troubles while building from git with XSL
enabled. It fails to compile on my system after hundreds of warnings. I just disabled it since I did
not even know why I left it enabled in the first place. I'm using libxml 2.9.7 from homebrew.


Previous Comments:
------------------------------------------------------------------------
[2018-12-08 13:16:07] cmb@php.net

This *might* be another manifestation of bug #77193.  Please try
again with the fix[1] applied, or with a recent Git snapshot.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=ef1269d5c158afaf052e3d79591462e0f5372b1a>

------------------------------------------------------------------------
[2018-12-08 09:24:33] sbarex at gmail dot com

I have same problem with php 7.3 installed via homebrew on mojave (both with bottle package or
compiled from source).
If i use xdebug extension no page can be viewed (php-fpm kill the child process).
If use php from command line without xdebug php works but kill when I use pcre functions.
Also if I use psysh (REPL cli) php crash on every command.
In all cases the code "crashed on child side of fork pre-exec" on php_pcre2_jit_compile or
php_pcre2_jit_match.

This is a crash report:

Process:               php [24544]
Path:                  /usr/local/Cellar/php/7.3.0/bin/php
Identifier:            php
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        ??? [24543]
Responsible:           php [24544]
User ID:               501

Date/Time:             2018-12-07 21:58:04.395 +0100
OS Version:            Mac OS X 10.14.2 (18C54)
Report Version:        12
Bridge OS Version:     3.2 (16P2542)

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000106928478
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [24544]

VM Regions Near 0x106928478:
    MALLOC_LARGE           0000000106828000-0000000106918000 [  960K] rw-/rwx SM=COW  
--> 
    VM_ALLOCATE            0000000106a00000-0000000107000000 [ 6144K] rw-/rwx SM=COW  

Application Specific Information:
crashed on child side of fork pre-exec

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   php                           	0x0000000102d4a4fe jit_compile + 42782
1   php                           	0x0000000102d3fd82 php_pcre2_jit_compile + 78
2   php                           	0x0000000102d8371b pcre_get_compiled_regex_cache + 1808
3   php                           	0x0000000102d8725b php_do_pcre_match + 203
4   php                           	0x00000001030f4116 ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER + 81
5   php                           	0x00000001030abd32 execute_ex + 98
6   php                           	0x00000001030abeae zend_execute + 318
7   php                           	0x0000000103070cfa zend_execute_scripts + 277
8   php                           	0x000000010301c58f php_execute_script + 639
9   php                           	0x000000010311c78b do_cli + 3857
10  php                           	0x000000010311b70c main + 1108
11  libdyld.dylib                 	0x00007fff7a21ced9 start + 1

------------------------------------------------------------------------
[2018-12-07 17:15:49] cmb@php.net

@nikic Indeed, you're right.  This is not about the JIT stack,
but rather about the machine stack.  From the docs[1]:

| There is a limit to the size of pattern that JIT supports,
| imposed by the size of machine stack that it uses.

I found an SO question which may be related[2], in which case this
wouldn't be Wordpress specific.

[1] <https://www.pcre.org/current/doc/html/pcre2jit.html#SEC3>
[2] <https://stackoverflow.com/questions/52718706/php-pcre2-no-more-memory>

------------------------------------------------------------------------
[2018-12-07 14:05:30] nikic@php.net

@cmb: Wouldn't that generate a JIT_STACKLIMIT rather than NOMEMORY error?

------------------------------------------------------------------------
[2018-12-07 14:03:32] cmb@php.net

> Warning: preg_match_all(): JIT compilation failed: no more
> memory

This warning is trigged, because pcre2_jit_compile() returns
PCRE2_ERROR_NOMEMORY, which hints at a too small JIT stack.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=77260


--
Edit this bug report at https://bugs.php.net/bug.php?id=77260&edit=1


Thread (29 messages)

« previous php.bugs (#218367) next »