Bug #81180 [NEW]: Using preg_match,preg_match_all even for non-matching conditions will cause php
From: noreply at example dot com
Operating system: Windows,freebsd
PHP version: 7.4.20
Package: *Regular Expressions
Bug Type: Bug
Bug description:Using preg_match,preg_match_all even for non-matching conditions will cause php
Description:
------------
FUNCTION: preg_match_all, preg_match
pattern : \S* \w* \>
|([\S]*)a\>|
|([\w]*)a\>|
subject : 25k byte over causes intolerable delay
> : two or more
other byte : any byte
$matches = array();
$pattern = '|'. '([\w]*)'. preg_quote('a>') .'|';
$subject = '>'.str_repeat('1', 500000).'>';
preg_match_all($pattern, $subject, $matches);
In a general programming language, if you pass a parameter with the same
conditions to a regular expression function, it will respond in 0
seconds.
Test script:
---------------
printf("PHP(%s,%s) ", phpversion(), php_sapi_name());
$pattern = '|'. '([\S]*)'. preg_quote('a>') .'|'; // \w
\S
printf("pattern : $pattern\n");
foreach(array(1,10,25,50,100,250,500) as $i)
{
$datasize = $i*1000; $matches = array();
$subject = '>'.str_repeat('1', $datasize-2).'>';
$starttime = microtime(true);
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER); //
php freeze very long time
$elapsedtime = (microtime(true) - $starttime);
printf("%3.0fKB %8.2f sec\n", $datasize/1000, $elapsedtime);
}
Expected result:
----------------
The runtime is 0 or few secounds.
Actual result:
--------------
PHP(8.0.7,cli) pattern : |([\S]*)a\>|
1KB 0.01 sec
10KB 0.20 sec
25KB 1.41 sec
50KB 5.78 sec
100KB 23.47 sec
250KB 150.56 sec
500KB 634.99 sec
PHP(7.4.20,cli) pattern : |([\S]*)a\>|
1KB 0.02 sec
10KB 0.24 sec
25KB 1.37 sec
50KB 5.82 sec
100KB 23.47 sec
250KB 146.89 sec
500KB 647.91 sec
PHP(7.3.28,cli) pattern : |([\S]*)a\>|
1KB 0.00 sec
10KB 0.00 sec
25KB 0.00 sec
50KB 0.00 sec
100KB 0.00 sec
250KB 0.00 sec
500KB 0.00 sec
--
Edit bug report at https://bugs.php.net/bug.php?id=81180&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81180&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81180&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81180&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81180&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81180&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81180&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81180&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81180&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81180&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81180&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81180&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81180&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81180&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81180&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81180&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81180&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81180&r=mysqlcfg
Thread (2 messages)
- noreply at example dot com