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

From: Date: Thu, 03 Oct 2019 18:57:36 +0000
Subject: Bug #77260 [Com]: preg_match_all(): JIT compilation failed: no more memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223026@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 Comment by: ilya at ilya dot pp dot ua Reported by: ettore at themecraft dot studio Summary: preg_match_all(): JIT compilation failed: no more memory Status: No Feedback Type: Bug Package: PCRE related Operating System: macOS 10.13.6 PHP Version: 7.3.0 Assigned To: nikic Block user comment: N Private report: N New Comment: openSUSE Tumbleweed php 7.3.10 pcre2 10.33 (patch from nickic aplayed) If pcre.jit=1 phpMyadmin login page show errors mod_fcgid: stderr: PHP Warning: preg_replace_callback(): JIT compilation failed: no more memory https://bugzilla.suse.com/show_bug.cgi?id=1124446 Please explain what feedback do you expect and what else do you need to provide? Previous Comments: ------------------------------------------------------------------------ [2019-09-29 04:22:08] php-bugs at lists dot php dot net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. ------------------------------------------------------------------------ [2019-09-18 08:50:34] nikic@php.net I've applied https://github.com/php/php-src/commit/03efeda53852842fe1a40240fce6793bba617959 and https://github.com/php/php-src/commit/e11ed028706dbedc51ba71736de21db15890a1c0, which should both fix the "no more memory" error on 10.13 and the segfaults on 10.14. If someone could confirm that the issue is resolved, that would be great. ------------------------------------------------------------------------ [2019-09-17 21:41:31] nikic@php.net Relevant discussion: https://bugs.exim.org/show_bug.cgi?id=2334 Unfortunately there's still the issue with MAP_JIT and fork() being incompatible, leading to the issue mentioned by sbarex at gmail dot com. It doesn't look like progress on avoiding that issue has been made. ------------------------------------------------------------------------ [2019-09-17 21:28:03] nikic@php.net I'm afraid that this bug report has ended up as a meta-issues for all kinds of mmap failures in pcre jit, which may not all have the same root cause. I think the original problem and what is affecting macOS users is the fact that PCRE2 has introduced use of MAP_JIT to be compatible with macOS 10.14. However, MAP_JIT is badly broken on macOS 10.13. We need to backport the following diff from PCRE2 10.33 to the 7.3 branch: diff --git a/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c b/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c index 7c18578618cf..3b37a9751f81 100644 --- a/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c +++ b/ext/pcre/pcre2lib/sljit/sljitExecAllocator.c @@ -94,6 +94,46 @@ static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size) #else +#ifdef __APPLE__ +/* Configures TARGET_OS_OSX when appropriate */ +#include <TargetConditionals.h> + +#if TARGET_OS_OSX && defined(MAP_JIT) +#include <sys/utsname.h> +#endif /* TARGET_OS_OSX && MAP_JIT */ + +#ifdef MAP_JIT + +static SLJIT_INLINE int get_map_jit_flag() +{ +#if TARGET_OS_OSX + /* On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a version + of macOS where it's OK to have more than one JIT block. On non-macOS systems, returns + MAP_JIT if it is defined. */ + static int map_jit_flag = -1; + + /* The following code is thread safe because multiple initialization + sets map_jit_flag to the same value and the code has no side-effects. + Changing the kernel version witout system restart is (very) unlikely. */ + if (map_jit_flag == -1) { + struct utsname name; + + uname(&name); + + /* Kernel version for 10.14.0 (Mojave) */ + map_jit_flag = (atoi(name.release) >= 18) ? MAP_JIT : 0; + } + + return map_jit_flag; +#else /* !TARGET_OS_OSX */ + return MAP_JIT; +#endif /* TARGET_OS_OSX */ +} + +#endif /* MAP_JIT */ + +#endif /* __APPLE__ */ + static SLJIT_INLINE void* alloc_chunk(sljit_uw size) { void *retval; @@ -103,17 +143,17 @@ static SLJIT_INLINE void* alloc_chunk(sljit_uw size) int flags = MAP_PRIVATE | MAP_ANON; #ifdef MAP_JIT - flags |= MAP_JIT; + flags |= get_map_jit_flag(); #endif retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0); -#else +#else /* !MAP_ANON */ if (dev_zero < 0) { if (open_dev_zero()) return NULL; } retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero, 0); -#endif +#endif /* MAP_ANON */ return (retval != MAP_FAILED) ? retval : NULL; } ------------------------------------------------------------------------ [2019-09-17 20:38:34] robertwildling at gmail dot com I work with TYPO3. In the course of updating older versions, this same exact error happened to me, too. Turning of pcre_jit is no option, because TYPO3 won't work then. So I moved down to php 7.2.22. The interesting thing is that the error logger of TYPO3 catches the same preg* errors, too, but the system does not crash. I am also on macos HighSierra with a brew installation. ------------------------------------------------------------------------ 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

« previous php.bugs (#223026) next »