Bug 252183 - a2ps hangs indefinitely while processing perl regex
a2ps hangs indefinitely while processing perl regex
Status: CLOSED RAWHIDE
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: a2ps (Show other bugs)
5.0
i386 Linux
low Severity medium
: ---
: ---
Assigned To: Tim Waugh
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-08-14 12:04 EDT by Brandon Poyner
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version: 4.13b-69.fc8
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-09-26 05:52:39 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Brandon Poyner 2007-08-14 12:04:50 EDT
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 13:40:36 EDT
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 14:19:19 EDT
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 05:52:39 EDT
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.