develooper Front page | perl.perl5.porters | Postings from April 2007

[perl #42721] Perl in Indefinite loop when trying to match regexp

From:
douglas . magno @ ufrj . br
Date:
April 26, 2007 03:41
Subject:
[perl #42721] Perl in Indefinite loop when trying to match regexp
Message ID:
rt-3.6.HEAD-30557-1177535238-626.42721-75-0@perl.org
# New Ticket Created by  douglas.magno@ufrj.br 
# Please include the string:  [perl #42721]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42721 >


This is a bug report for perl from douglasmagno+perl@gmail.com,
generated with the help of perlbug 1.35 running under perl v5.8.8.


-----------------------------------------------------------------
[Please enter your report here]

We've found a bug in Perl's regular expression, which leads to
indefinite loop with high memory and CPU usage. We have prepared a
Test Case to reproduce the problem.


THE PROBLEM:
Trying to match the following regular expression:
/ID\s+(\d+)\s+VID\s+(\d+)\s+JID\s+(\d+)\s+INFO:\s+FTP\s+done.*profile:\s+([^\s]+).*titulo:([^|]+).*duracao:\s+(\d+).*filesize:\s+(\d+).*md5sum:\s+(\w+).*sourcePath:\s+([^\s]+).*uploadPath:\s([^\s]+).*isRetry:\s+(\d+)/

with the following string:
"ftp.pl[13997]: ID 2883 VID 637818 JID 3702 INFO: FTP done | profile:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | titulo: BBBBBBBB BBBBBBB BB BBBB
BB BBBBBB BBBBBBBB BBB BBBBBB BBBBBBB BBBBBB B BBBBBBBB | duracao:
103369 | filesize: 9304367 | md5sum: 8d00621d9c60596cc79ce46d91cb1809
| sourcePath: /usr/local/cccccc/cccccc/cccccccccccccccccc.ccc |
uploadPath: /dddddd/dddddddddd//2007/02/13/DDDDDDDDDDDDD_dddd.ddd |
isRetry:"

The perl loop indefinetly....



TEST CASE:
The problem can be reproduced by simply executing the Perl RegExp Debugger:
--------------------------------------------------------------------------------
perl -Dr -e '"ftp.pl[13997]: ID 2883 VID 637818 JID 3702 INFO: FTP
done | profile: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | titulo: BBBBBBBB
BBBBBBB BB BBBB BB BBBBBB BBBBBBBB BBB BBBBBB BBBBBBB BBBBBB B
BBBBBBBB | duracao: 103369 | filesize: 9304367 | md5sum:
8d00621d9c60596cc79ce46d91cb1809 | sourcePath:
/usr/local/cccccc/cccccc/cccccccccccccccccc.ccc | uploadPath:
/dddddd/dddddddddd//2007/02/13/DDDDDDDDDDDDD_dddd.ddd | isRetry:" =~
/ID\s+(\d+)\s+VID\s+(\d+)\s+JID\s+(\d+)\s+INFO:\s+FTP\s+done.*profile:\s+([^\s]+).*titulo:([^|]+).*duracao:\s+(\d+).*filesize:\s+(\d+).*md5sum:\s+(\w+).*sourcePath:\s+([^\s]+).*uploadPath:\s([^\s]+).*isRetry:\s+(\d+)/;'
--------------------------------------------------------------------------------
...and we get a indefinite loop in the debugger.

If we change the tail of the regexp from
.*isRetry:\s+(\d+)
to:
.*isRetry:\s*(\d+)?

The problem dissapears, as can be seen when executing:

--------------------------------------------------------------------------------
perl -Dr -e '"ftp.pl[13997]: ID 2883 VID 637818 JID 3702 INFO: FTP
done | profile: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | titulo: BBBBBBBB
BBBBBBB BB BBBB BB BBBBBB BBBBBBBB BBB BBBBBB BBBBBBB BBBBBB B
BBBBBBBB | duracao: 103369 | filesize: 9304367 | md5sum:
8d00621d9c60596cc79ce46d91cb1809 | sourcePath:
/usr/local/cccccc/cccccc/cccccccccccccccccc.ccc | uploadPath:
/dddddd/dddddddddd//2007/02/13/DDDDDDDDDDDDD_dddd.ddd | isRetry:" =~
/ID\s+(\d+)\s+VID\s+(\d+)\s+JID\s+(\d+)\s+INFO:\s+FTP\s+done.*profile:\s+([^\s]+).*titulo:([^|]+).*duracao:\s+(\d+).*filesize:\s+(\d+).*md5sum:\s+(\w+).*sourcePath:\s+([^\s]+).*uploadPath:\s([^\s]+).*isRetry:\s*(\d+)?/;'
--------------------------------------------------------------------------------

We've executed the same tests in Perl development version 5.9.4 with
the same results.

Thanks folks.

Douglas Magno
douglasmagno+perl@gmail.com
Globo.com
Rio de Janeiro - Brazil


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=
    severity=
---
Site configuration information for perl v5.8.8:

Configured by dmagno at Thu Apr 19 17:05:46 BRT 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.20-1.2933.fc6, archname=i686-linux
    uname='linux localhost.localdomain 2.6.20-1.2933.fc6 #1 smp mon
mar 19 11:38:26 edt 2007 i686 i686 i386 gnulinux '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DDEBUGGING -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-DDEBUGGING -I/usr/include/gdbm'
    ccversion='', gccversion='4.1.1 20070105 (Red Hat 4.1.1-51)',
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='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.8:
    /tmp/perl/lib/5.8.8/i686-linux
    /tmp/perl/lib/5.8.8
    /tmp/perl/lib/site_perl/5.8.8/i686-linux
    /tmp/perl/lib/site_perl/5.8.8
    /tmp/perl/lib/site_perl
    .

---
Environment for perl v5.8.8:
    HOME=/home/dmagno
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/jre1.5.0_09/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/opt/jre1.5.0_09/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/dmagno/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About