|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23616 preg_match() segfault
Submitted: 2003-05-13 15:33 UTC Modified: 2003-05-15 09:21 UTC
From: cestmir at nustep dot net Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.2-RC3-dev OS: Linux Debian, Win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 - 18 = ?
Subscribe to this entry?

 [2003-05-13 15:33 UTC] cestmir at nustep dot net
This code causes a segfault both on Linux and Win32 builds.


function utf8IsValidString($AStr)
  $ptrASCII  = '[\x00-\x7F]';
  $ptr2Octet = '[\xC2-\xDF][\x80-\xBF]';
  $ptr3Octet = '[\xE0-\xEF][\x80-\xBF]{2}';
  $ptr4Octet = '[\xF0-\xF4][\x80-\xBF]{3}';
  $ptr5Octet = '[\xF8-\xFB][\x80-\xBF]{4}';
  $ptr6Octet = '[\xFC-\xFD][\x80-\xBF]{5}';

  return preg_match("/^($ptrASCII|$ptr2Octet|$ptr3Octet|$ptr4Octet|$ptr5Octet|$ptr6Octet)*$/s", $AStr);

// read text
$handle = fopen('utf8text.txt', 'r');
$stat = fstat($handle);
$str = fread($handle, $stat['size']);

// execute PCRE match
var_dump(utf8IsValidString("some short text \xC4\xBE\xC5\xA1")); // ok
var_dump(utf8IsValidString($str));                               // segfault


This code including data file to reproduce bug can be found here:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-13 15:44 UTC]
Related to bug #13618
 [2003-05-13 15:48 UTC]
and related to bug #20698. a PCRE library limitation.
 [2003-05-15 09:21 UTC]
Not PHP bug.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 03:01:33 2024 UTC