php-src icon indicating copy to clipboard operation
php-src copied to clipboard

PCRE2 Matching error introduced in 7.4.7

Open ghost opened this issue 4 years ago • 3 comments

Description

Starting with PHP 7.4.7 PCRE2 {x} no longer matches but {x-1,x+1} does. For a more full explanation see this bug off another project where the project owner was like "upstream and here is proof, go file with PHP" so here I am :)

basically with the string "aa" [a]{1,3} matches but [a]{2} does not as of PHP 7.4.7.

https://github.com/firasdib/Regex101/issues/1704#issuecomment-1019503942

PHP Version

PHP 7.4.7

Operating System

No idea, whatever Tenable Security Center runs.

ghost avatar Jan 23 '22 22:01 ghost

Minimal example to reproduce the problem:

https://3v4l.org/YmfGg

var_dump(preg_match('~[Aa]{2}~', 'aa'));

Output for 7.4.6 - 7.4.27, 8.0.1 - 8.0.15, 8.1.0 - 8.1.2 int(0)

Output for 7.4.0 - 7.4.5 int(1)

However, we're not maintaining the PCRE2 library, we're just using it. So the correct place to raise the issue would probably be here: https://github.com/PhilipHazel/pcre2/issues

iluuu1994 avatar Jan 23 '22 22:01 iluuu1994

PHP is currently on PCRE2 10.39, which is the latest version. 3v4l says the problem started in 7.4.6 which corresponds to PCRE2 10.34, and looking through the changelog I do see a handful of changes regarding single-character repetition between then and now.

Bug aside, that regex makes my eyes bleed.

damianwadley avatar Jan 23 '22 22:01 damianwadley

Just an aside at @damianwadley as I feel his pain, yeah Tenable Security Center doesn't allow case insensitivity for it's PCRE asset matching and sys admins can't be counted on to consistently case DNS A records so it leads to nightmares like that lol. I got hundreds of similar ones, some even more atrocious.

And yes I have literally seen in my zone file (even right now): Server1, server2, SERVER3, SeRvEr4, SerVer5 ...

Just empathizing at the eye cancer lol.

ghost avatar Jan 24 '22 23:01 ghost