Hi Anatol,

Anatol Belski wrote:

>> -----Original Message-----
>> From: Christoph Becker [mailto:cmbecke...@gmx.de]
>> Sent: Saturday, July 25, 2015 2:25 AM
>> To: Anatol Belski <anatol....@belski.net>; 'Pierre Joye'
>> <pierre....@gmail.com>
>> Cc: 'PHP internals' <internals@lists.php.net>
>> Subject: Re: [PHP-DEV] PCRE JIT stack size limit
>>
>> I would not suggest to change the return value of preg_match() and friends.
>> FALSE seems to be appropriate here.  Instead I suggest to add a new error
>> constant which would be returned from preg_last_error().
>>
> Yep, sounds feasible. At least users can be informed about this kind of 
> error, seems a constant is feasible for 7.0.

That would be nice.  I'll make a respective PR.

> Btw I've just noticed that the snippet I've posted earlier won't currently 
> work. 
> 
> If (false === preg_match(",evil pattern,", ...)) {
>                If (OUT_OF_JIT_STACK == pcre_last_error()) {
>           ini_set("pcre.jit", 0);
>           // retry
>       }
>  }
> 
> The retry would fail even when JIT is disabled on demand. This is actually 
> rather unexpected, maybe something in PCRE JIT state cannot be recovered once 
> JIT compilation has failed. But actually, even without running into 
> debugging, it is also a bad sign telling that the behavior can get 
> complicated (

Indeed!  That's caused by our PCRE cache.  The cached regex is alread
studied with JIT info, as all that happens in
pcre_get_compiled-regex_cache[1].  So switching pcre.jit at runtime may
not have the desired effect.  I'm not sure if that has to be regarded as
bug, and whether we should do something about it.  One solution might be
to clear the regex cache whenever the ini setting changes.  I'll have a
closer look.

> Running for the INI option and some custom JIT stack functionality needs more 
> brainstorming and test. Please ping when you have an initial implementation, 
> I'd be glad to help testing, etc. anyway.

All in all it seems that we probably should have an RFC for that.  I'll
consider to write one, but there's no need to hurry – too late for 7.0
anyway. :)

[1]
<https://github.com/php/php-src/blob/php-7.0.0beta2/ext/pcre/php_pcre.c#L257>

-- 
Christoph M. Becker

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to