note 118805 added to function.preg-match-all

From: Date: Tue, 09 Feb 2016 11:56:00 +0000
Subject: note 118805 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-204903@lists.php.net to get a copy of this message
Be careful with this pattern match and large input buffer on preg_match_* functions. <?php $pattern = '/\{(?:[^{}]|(?R))*\}/'; preg_match_all($pattern, $buffer, $matches); ?> if $buffer is 80+ KB in size, you'll end up with segfault! [89396.588854] php[4384]: segfault at 7ffd6e2bdeb0 ip 00007fa20c8d67ed sp 00007ffd6e2bde70 error 6 in libpcre.so.3.13.1[7fa20c8c3000+3c000] This is due to the PCRE recursion. This is a known bug in PHP since 2008, but it's source is not PHP itself but PCRE library. Rasmus Lerdorf has the answer: https://bugs.php.net/bug.php?id=45735#1365812629 "The problem here is that there is no way to detect run-away regular expressions here without huge performance and memory penalties. Yes, we could build PCRE in a way that it wouldn't segfault and we could crank up the default backtrack limit to something huge, but it would slow every regex call down by a lot. If PCRE provided a way to handle this in a more graceful manner without the performance hit we would of course use it." ---- Server IP: 72.52.91.14 Probable Submitter: 89.216.22.59 ---- Manual Page -- http://php.net/manual/en/function.preg-match-all.php Edit -- https://master.php.net/note/edit/118805 Del: integrated -- https://master.php.net/note/delete/118805/integrated Del: useless -- https://master.php.net/note/delete/118805/useless Del: bad code -- https://master.php.net/note/delete/118805/bad+code Del: spam -- https://master.php.net/note/delete/118805/spam Del: non-english -- https://master.php.net/note/delete/118805/non-english Del: in docs -- https://master.php.net/note/delete/118805/in+docs Del: other reasons-- https://master.php.net/note/delete/118805 Reject -- https://master.php.net/note/reject/118805 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204903) next »