Jump to content

[SOLVED] preg_match crashes PHP


phant0m

Recommended Posts

I have reinstalled my computer and therefore a newer version of XAMPP.

 

This now leads to strange results with preg_match.

Consider the following code:

<?php
$string = 'asdfsadfasdf asdfa adsf dsa fdsa fdsa dsa fdsa fdsaf dsa dsa fdsa fdsaf sad fdsf sad dsfgdsfg 
asdfsadfadfsadfasdadffa aa fddsaf sad fdsf sadfasdf asaaaaadfa adsf dsa fdsa fdsa dsa fdsaa  dsa faaaaaaaadaaaaaaaaaaaasaf dsa faaaaadaaaaaaaaaasaf dsa dsa fdsa fdsaf sad fdsf sad daaaaasfgdsfg asdfsadfaaaasdf asdfa adsf dsa fdsa fdsa dsa fdsa fdsaf dsa dsa fdsa fdsaf sad fdasf asad dsfgdsfg aaaaaa';
 $pattern=  preg_match('%^(?:
              [\x09\x0A\x0D\x20-\x7E]            # ASCII
            | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
            |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
            | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
            |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
            |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
            | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
            |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
      )*$%xs';
preg_match($pattern, $string);

?>

 

This code works. However, if I was to insert one single character more in $string, PHP crashes without telling me why.

 

 

[Wed Jul 22 21:51:08 2009] [notice] Parent: child process exited with status 3221225477 -- Restarting.

 

 

 

 

The string is very often much longer than that, and online it works flawlessly.

 

This is online:

PHP Version 5.2.6

 

PCRE Library Version 6.6 06-Feb-2006

pcre.backtrack_limit 100000

pcre.recursion_limit 100000

 

This is offline:

PHP Version 5.2.9

 

PCRE Library Version 7.8 2008-09-05

pcre.backtrack_limit 100000

pcre.recursion_limit 100000

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/
Share on other sites

I encountered a similar problem, trying to validate utf-8: on some servers the preg_match ran without problems, on others it simply crashed without error. Suspected that it was related to the regexp library versions, but resolved it by using

$charset = (mb_check_encoding($string,'ISO-8859-1')) ? 'ISO-8859-1' : 'UTF-8';

instead

 

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.