Bug #70699 [Opn]: Regex limits on repeating patterns

From: Date: Mon, 12 Oct 2015 23:05:16 +0000
Subject: Bug #70699 [Opn]: Regex limits on repeating patterns
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196580@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70699&edit=1

 ID:                 70699
 Updated by:         rasmus@php.net
 Reported by:        bugs dot php dot net at ss dot st dot tc
 Summary:            Regex limits on repeating patterns
 Status:             Open
 Type:               Bug
 Package:            *Regular Expressions
 Operating System:   OSX and Linux
 PHP Version:        7.0.0RC4
 Block user comment: N
 Private report:     N

 New Comment:

Well, if you read that pcre doc closely, you aren't actually hitting the backtrack limit. What
is happening is that the jit is running for too long in which case pcre returns the same
PCRE_ERROR_MATCHLIMIT error you get when hitting the match limit without the JIT. I agree this is an
annoying api from pcre, but short of patching pcre I am not sure what we can do about it unless
there is some other knows we can tune on the jit.

Your example doesn't actually backtrack that much. To get the same output in PHP 5.5 you have
to set pcre.backtrack_limit=2732

So one way to ensure your stuff will work with the jit might be to lower your backtrack_limit way
down to something like 1000 and make sure all your regular expressions are optimized to not
backtrack very far. That will make them run a lot faster too. Or turn off the jit.


Previous Comments:
------------------------------------------------------------------------
[2015-10-12 22:35:36] bugs dot php dot net at ss dot st dot tc

I see. But still don't know where to go from here.
Even though I can use preg_last_error() to figure out the error, I can't disable jit
temporarily to perform a desired match (ini_set() doesn't actually enable/disable jit, although
it does change runtime ini value (is that expected behaviour?)).
I understand that backtracking can be catastrophic sometimes, yet I didn't expect jit to bump
me that fast.
Giving up jit totally by setting ini value to 0 would be my last resort.
I'm lost, confused, depressed.

------------------------------------------------------------------------
[2015-10-12 22:11:52] rasmus@php.net

This is getting more into a PCRE question than a PHP one. See: http://www.pcre.org/original/doc/html/pcrejit.html
where it says:

  The error code PCRE_ERROR_MATCHLIMIT is returned by the JIT code if searching a 
  very large pattern tree goes on for too long, as it is in the same 
  circumstance when JIT is not used, but the details of exactly what is counted 
  are not the same. The PCRE_ERROR_RECURSIONLIMIT error code is never returned 
  by JIT execution.

------------------------------------------------------------------------
[2015-10-12 22:01:17] bugs dot php dot net at ss dot st dot tc

You're right Rasmus, jit was the reason. So how do we control the limits with jit then?

------------------------------------------------------------------------
[2015-10-12 21:37:25] rasmus@php.net

The limits work a bit different with the jit enabled I think. I bet if you set pcre.jit=0 in PHP 7
you will get the same result.

------------------------------------------------------------------------
[2015-10-12 21:32:05] bugs dot php dot net at ss dot st dot tc

pcre.backtrack_limit is set to default value of 1000000 in both configurations.

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


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=70699


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


Thread (11 messages)

« previous php.bugs (#196580) next »