php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33640 preg_match will cause a segmentation fault on pattern
Submitted: 2005-07-11 08:53 UTC Modified: 2005-07-11 09:29 UTC
From: david dot tulloh at infaze dot com dot au Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5CVS-2005-07-11 (dev) OS: debian linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david dot tulloh at infaze dot com dot au
New email:
PHP Version: OS:

 

 [2005-07-11 08:53 UTC] david dot tulloh at infaze dot com dot au
Description:
------------
While trying to craft a relatively complex regex string I caused php to consistently segfault.  I then tracked it down to a smaller simpler pattern.


PHP 5.1.0-dev (cli) (built: Jul  6 2005 10:55:39)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0-dev, Copyright (c) 1998-2004 Zend Technologies


Reproduce code:
---------------
<?php
preg_match('/(?(?=a) (?R) )/x', 'a', $arr);
preg_match_all('/(?(?=a) (?R) )/x', 'a', $arr);
echo 'fin', "\n";  # will never print
?>

Either preg line will cause the fault.

Expected result:
----------------
Anything but a segmentation fault, some kind of error would be nice.

Actual result:
--------------
Segmentation fault

gdb:
Starting program: /usr/bin/php -f pcrash.php
[Thread debugging using libthread_db enabled]
[New Thread -1211468032 (LWP 22573)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211468032 (LWP 22573)]
0xb7f58362 in pcre_compile () from /usr/lib/libpcre.so.3


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-11 08:58 UTC] david dot tulloh at infaze dot com dot au
It looks like the segfault actually originates from within libpcre.  I'm going to try a newer version.

Is there anyway for php to catch the library as it falls over?
 [2005-07-11 09:29 UTC] sniper@php.net
You're hitting the PCRE limitations: http://www.pcre.org/pcre.txt

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 17:01:33 2025 UTC