Hi folks,

I've run into a nasty segfault that I suspect is related to deeply
recursive regular expressions.  The odd thing is that just a deeply
recursive regex won't trigger this bug by itself, it must be run in
combination with another regex.  Please see the test case below.

Cheers,

-J
--

test.pl
--
#!/usr/bin/perl

use strict;
use warnings;

use Regexp::Common qw( balanced );

open(my $file, shift) or die "can't open file: $!";
my $text = do {local $/; <$file> };
close($file) or die "can't close file: $!";

# possible bug in the regex engine?  When combined, these two regexes
# cause segfaults on Linux/x86 w/ perl 5.8.5, 5.8.6, & 5.8.7 & on
# Linux/amd64 w/ perl 5.8.5.  There seems to be some dependance on the
# size of text file being parsed.  It appears that the minimuze number
# of lines is ~11K on my systems.

# strip C++ style comments
$text =~ s| // [^\n]* ||gx; # leave the \n

# strip C block style comments
# this regex has quoting issues inside a s/// or qr//
my $block_remover = $RE{balanced}{-begin => "/*"}{-end => "*/"};
$text =~ s/$block_remover//sg;
--

howto reproduce the segfault:
--
find /usr/include/ -name "*.h" -exec cat {} \; > include.txt
./test.pl include.txt
Segmentation fault
--

gdb backtrace
--
(gdb) run test.pl include.txt
Starting program: /usr/bin/perl test.pl include.txt
[Thread debugging using libthread_db enabled]
[New Thread -1208052032 (LWP 14674)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208052032 (LWP 14674)]
0x0812e38f in Perl_regexec_flags ()
(gdb) bt
#0  0x0812e38f in Perl_regexec_flags ()
#1  0x0813390e in Perl_regexec_flags ()
#2  0x08133151 in Perl_regexec_flags ()
#3  0x08133151 in Perl_regexec_flags ()
#4  0x081327cb in Perl_regexec_flags ()
#5  0x08133fc8 in Perl_regexec_flags ()
#6  0x08133151 in Perl_regexec_flags ()
#7  0x08133151 in Perl_regexec_flags ()
#8  0x0812e91a in Perl_regexec_flags ()
#9  0x08132f73 in Perl_regexec_flags ()
#10 0x08133151 in Perl_regexec_flags ()
.
.
(and so on into the thousands)
--

perlbug -d
--
Flags:
    category=
    severity=
---
Site configuration information for perl v5.8.7:

Configured by Gentoo at Fri Jul  1 11:56:11 HST 2005.

Summary of my perl5 (revision 5 version 8 subversion 7) configuration:
  Platform:
    osname=linux, osvers=2.6.11-gentoo-r9,
archname=i686-linux-thread-multi
    uname='linux moanui 2.6.11-gentoo-r9 #1 thu jun 9 14:59:30 hst 2005
i686 intel(r) pentium(r) m processor 2.00ghz genuineintel gnulinux '
    config_args='-des -Darchname=i686-linux-thread -Dcccdlflags=-fPIC
-Dccdlflags=-rdynamic -Dcc=i686-pc-linux-gnu-gcc -Dprefix=/usr
-Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-O2
-mcpu=pentium3 -pipe -g -Duselargefiles -Dd_semctl_semun
-Dscriptdir=/usr/bin -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3
-Dinstallman1dir=/var/tmp/portage/perl-5.8.7/image//usr/share/man/man1
-Dinstallman3dir=/var/tmp/portage/perl-5.8.7/image//usr/share/man/man3
-Dman1ext=1 -Dman3ext=3pm -Dinc_version_list=5.8.0
5.8.0/i686-linux-thread-multi 5.8.2 5.8.2/i686-linux-thread-multi 5.8.4
5.8.4/i686-linux-thread-multi 5.8.5 5.8.5/i686-linux-thread-multi 5.8.6
5.8.6/i686-linux-thread-multi  -Dcf_by=Gentoo -Ud_csh -Dusethreads
-Di_ndbm -Di_gdbm -Di_db'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='i686-pc-linux-gnu-gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE
-DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -mcpu=pentium3 -pipe -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING
-fno-strict-aliasing -pipe'
    ccversion='', gccversion='3.3.5-20050130 (Gentoo 3.3.5.20050130-r1,
ssp-3.3.5.20050130-1, pie-8.7.7.1)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='i686-pc-linux-gnu-gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.7:
    /etc/perl
    /usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl/5.8.6/i686-linux-thread-multi
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.7/i686-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.7
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.7/i686-linux-thread-multi
    /usr/lib/perl5/5.8.7
    /usr/local/lib/site_perl
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl/5.8.6/i686-linux-thread-multi
    .

---
Environment for perl v5.8.7:
    HOME=/home/moanui/jhoblitt
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.3.5-20050130:/usr/i386-pc-linux-gnu/gcc-bin/3.3:/usr/qt/3/bin:/usr/kde/3.3/bin:/usr/games/bin:/home/moanui/jhoblitt/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

Attachment: pgp65qun0JaY1.pgp
Description: PGP signature

Reply via email to