Bug 252183 - a2ps hangs indefinitely while processing perl regex
Summary: a2ps hangs indefinitely while processing perl regex
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: a2ps
Version: 5.0
Hardware: i386
OS: Linux
low
medium
Target Milestone: ---
: ---
Assignee: Tim Waugh
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2007-08-14 16:04 UTC by Brandon Poyner
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version: 4.13b-69.fc8
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-09-26 09:52:39 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Brandon Poyner 2007-08-14 16:04:50 UTC
Description of problem:
a2ps hangs indefinitely while processing a large perl regular expression,
consuming all available CPU.  

Version-Release number of selected component (if applicable):
a2ps-4.13b-57.1
  
How reproducible:
Every time

Steps to Reproduce:
1. Create file.pl with the following contents:

    #!/usr/bin/perl -w

    while(<IN>){
        # remove naughty characters
         
s/[^\w\.\s\|\,\'\<\>\?\;\:\[\]\-\_\=\+\`\~\!\@\#\$\%\^\&\*\(\)\/\?\{\}q]//g;
    }
    close IN;



2. Run: a2ps -o- file.pl
3. No results, command hangs, 99% cpu consumed
  
Actual results:


Expected results:


Additional info:
Possibly a problem with perl.ssh?  See
http://osdir.com/ml/printing.a2ps.bugs/2006-11/msg00000.html

Comment 1 Brandon Poyner 2007-08-16 17:40:36 UTC
While looking at this again, I noticed that the command will eventually
complete.  On a 2.2Ghz Pentium 4 CPU the above command took about 22.5 hours of
nearly dedicated CPU time to complete.  The resulting PostScript for the regex is:

(s) K
(/[^\\w\\.\\s\\|\\,\\'\\<\\>\\?\\;\\:\\[\\]\\-\\_\\=\\+\\`\\~\\!\\@\\#\\$\\%\\^\\&\\*\\\(\\\)\\/\\?\\{\\}q]//g;)
p n



Comment 2 Brandon Poyner 2007-09-25 18:19:19 UTC
I seem to have narrowed down that it is perl.ssh causing a2ps to take a long
time to complete.  The following modification to perl.ssh changes the completion
time from 22.5 hours to under 1 second.  However I don't know if this is a
_wise_ change to make.

===================================================================
RCS file: perl.ssh,v
retrieving revision 1.1
diff -C4 -r1.1 perl.ssh
*** perl.ssh    2007/09/25 14:38:25     1.1
--- perl.ssh    2007/09/25 18:15:09
***************
*** 105,115 ****
      # two regexps with a single char as delimiter
      (/(s|tr)/                 # 1. The command: `tr' or `s'
       /(([[:punct:]])/         # 2. The delimiter
       /(/                      # 3. The *two* regexps
!      /(.|\\\\.)*/             #   First regexp
       /\\3/                    #   Separator
!      /(.|\\\\.)*/             #   Second Regexp
       /)/                      #
       /\\3)/                   # Closer
       \1 Keyword_strong, \2 Plain),

--- 105,115 ----
      # two regexps with a single char as delimiter
      (/(s|tr)/                 # 1. The command: `tr' or `s'
       /(([[:punct:]])/         # 2. The delimiter
       /(/                      # 3. The *two* regexps
!      /(\\\\.)*/                       #   First regexp
       /\\3/                    #   Separator
!      /(\\\\.)*/                       #   Second Regexp
       /)/                      #
       /\\3)/                   # Closer
       \1 Keyword_strong, \2 Plain),



Comment 3 Tim Waugh 2007-09-26 09:52:39 UTC
Thanks for the patch.  I'm not sure either, but I don't think the consequences
can be much worse that the symptom so I'll try it out for Fedora 8
(a2ps-4.13b-69.fc8).

I'm not entirely convinced the patch is correct (in fact, it looks wrong in that
there are other places left with the original regexp regexp) so I'll hold off
from applying it in Red Hat Enterprise Linux for the time being.


Note You need to log in before you can comment on or make changes to this bug.