com php-src: Fix (*NO_JIT) usage when JIT is en abled: ext/pcre/php_pcre.c ext/pcre/tests/no_jit_ bug70110.phpt
| From: | Anatol Belski | Date: | Thu, 16 Nov 2017 13:12:05 +0000 |
| Subject: | com php-src: Fix (*NO_JIT) usage when JIT is en abled: ext/pcre/php_pcre.c ext/pcre/tests/no_jit_ bug70110.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100275@lists.php.net to get a copy of this message | ||
Commit: a370a6af647e27a334676a2c87bf686c6c973423
Author: Anatol Belski <ab@php.net> Thu, 16 Nov 2017 14:12:05 +0100
Parents: acaaf4608acd9d74b31d992a1afa94767fda912b
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a370a6af647e27a334676a2c87bf686c6c973423
Log:
Fix (*NO_JIT) usage when JIT is enabled
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.
Changed paths:
M ext/pcre/php_pcre.c
A ext/pcre/tests/no_jit_bug70110.phpt
Diff:
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 5386077..615cece 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -726,7 +726,10 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
/* 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);
diff --git a/ext/pcre/tests/no_jit_bug70110.phpt b/ext/pcre/tests/no_jit_bug70110.phpt
new file mode 100644
index 0000000..d1ce7ab
--- /dev/null
+++ b/ext/pcre/tests/no_jit_bug70110.phpt
@@ -0,0 +1,16 @@
+--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==