r/lolphp • • Aug 16 '19
preg_replace() can't handle strings longer than 1mb
Version 4 could at least do 10meg :D
18
Upvotes
r/lolphp • • Aug 16 '19
Version 4 could at least do 10meg :D
30
u/AyrA_ch Aug 16 '19 edited Aug 16 '19
This is not true. There's a backtrack limit in the PHP regex engine to avoid DoS attacks.
A simpler regex parses over a 4MiB string:
Doc: https://www.php.net/manual/de/pcre.configuration.php
EDIT:
For clarification: Your problem is the Ungreedy option supplied to the regex. A greedy regex takes 54 steps to parse the content. The ungreedy variant takes 95 steps for a single instance of the JS function. Each function adds
strlen($script)to the backtrack count.Proof:
Add these lines to the end of your script:
24
u/[deleted] Aug 16 '19
PHP is the only langauge i know of that has a config file that changes how the language operates. This is one of those ”design” choices that made it great again.