If (*NO_JIT) is put into the pattern, the JIT compilation will still
succeed but produce no code. The pattern will still have to be
interpreted and is not suitable for the JIT fast path. This means,
we still need to check the pattern info after JIT compilation and only
set the flags when the JIT code was produced.
/* Enable PCRE JIT compiler */
rc = pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);
if (EXPECTED(rc >= 0)) {
- poptions |= PREG_JIT;
+ size_t jit_size = 0;
+ if (!pcre2_pattern_info(re, PCRE2_INFO_JITSIZE, &jit_size) && jit_size > 0) {
+ poptions |= PREG_JIT;
+ }
} else {
pcre2_get_error_message(rc, error, sizeof(error));
php_error_docref(NULL, E_WARNING, "JIT compilation failed: %s", error);
--- /dev/null
+--TEST--
+Test (*NO_JIT) doesn't crash when JIT enabled
+--SKIPIF--
+<?php if (!PCRE_JIT_SUPPORT) die("skip pcre jit support required"); ?>
+--FILE--
+<?php
+
+var_dump(preg_match('/(*NO_JIT)^(A{1,2}B)+$$/',str_repeat('AB',8192)));
+var_dump(preg_match('~(*NO_JIT)(a)*~', str_repeat('a', 5431), $match))
+
+?>
+==DONE==
+--EXPECTF--
+int(1)
+int(1)
+==DONE==