php-src
php-src copied to clipboard
preg_match return false on a long string without warning or notice
Description
The following code:
<?php
error_reporting(E_ALL);
$regex = '/^\d+(?:(?:,\d+)+|:\d+)$/';
echo "range 1 - 8192\n";
var_dump(preg_match($regex, implode(',', range(1, 8192))));
echo "range 1 - 8193\n";
var_dump(preg_match($regex, implode(',', range(1, 8193))));
Resulted in this output:
range 1 - 8192
int(1)
range 1 - 8193
bool(false)
But I expected this output instead:
range 1 - 8192
int(1)
range 1 - 8193
bool(1) or notice message
http://sandbox.onlinephpfunctions.com/code/b5a6921f9b5beef87fee5bb6c25a359ba8b76702
PHP Version
8.0
Operating System
No response
PCRE functions report errors through preg_last_error/_msg.
In your case, the latter will tell you "JIT stack limit exhausted". https://3v4l.org/66PlR
If this is an actual problem for you, you can adjust the regex to match more at a time, eg. https://3v4l.org/oLkVh will give you about 3x as many numbers, or you can disable JIT with the pcre.jit=0 setting.