You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-dev@jakarta.apache.org by bu...@apache.org on 2001/04/02 11:54:49 UTC

[Bug 1179] New - Infinite loop when matching regular expression (Jakarta-ORO v2.0.1)

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1179

*** shadow/1179	Mon Apr  2 02:54:49 2001
--- shadow/1179.tmp.7261	Mon Apr  2 02:54:49 2001
***************
*** 0 ****
--- 1,98 ----
+ +============================================================================+
+ | Infinite loop when matching regular expression (Jakarta-ORO v2.0.1)        |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1179                        Product: ORO                     |
+ |       Status: NEW                         Version: 2.0.1                   |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Critical                 OS/Version:                         |
+ |     Priority:                           Component: Main                    |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: oro-dev@jakarta.apache.org                                   |
+ |  Reported By: Antti.Valtokari@iocore.fi                                    |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ The following code sample may be used reproduce infinite loop bug in
+ Jakarta-ORO v2.0.1. The bug exist with both the binary release and
+ classes compiled with Sun JDK 1.3 under Linux. The execution
+ environment is Borland JBuilder v4.0 with the JDK 1.3 attached.
+ 
+   /* This regex performs the match as required. */
+   private static String EXP = "%([a-z]*)\\(([a-z]*)\\)";
+ 
+   /* Using any of the following regular expression causes infinite
+ loop, if
+   the input string below contains three elements.
+ 
+   private static String EXP = "%?%([a-z]*)\\(([a-z]*)\\)";
+   private static String EXP = "(%?)%([a-z]*)\\(([a-z]*)\\)";
+   private static String EXP = "(%)?%([a-z]*)\\(([a-z]*)\\)";
+   private static String EXP = "[%]?%([a-z]*)\\(([a-z]*)\\)";
+   private static String EXP = "([%]?)%([a-z]*)\\(([a-z]*)\\)";
+   */
+ 
+   private void run() throws Exception {
+     PatternCompiler compiler = new Perl5Compiler();
+     PatternMatcher matcher = new Perl5Matcher();
+     Pattern pattern = compiler.compile(EXP);
+ 
+     /* Input with three elements that cause the infinite loop. */
+     PatternMatcherInput in = new
+ PatternMatcherInput("%a(a):%a(b):%a(c)");
+ 
+     /* Using this input does not cause any problems.
+     PatternMatcherInput in = new PatternMatcherInput("%a(a):%a(b)");
+     */
+ 
+     while(matcher.contains(in, pattern)) {
+       MatchResult result = matcher.getMatch();
+ 
+       for(int group = 1; group < result.groups(); group++) {
+         System.out.println(group + ": " + result.group(group));
+       }
+ 
+       System.out.println("----------------");
+     }
+   }
+ 
+ What I am trying to do is to match patterns in format %abc(def) from
+ input string and substitu them with other values. The bug caused the
+ substitution fail with StringIndexBoundsException and it seems that
+ the problem is on the Perl5Matcher -class.
+ 
+ If the input string contains the tree matchable substrings, using any
+ of the expressions having the sub-pattern for preceding precent -sign
+ causes the while -loop to never stop. If the first expression is used
+ or the input contains only two matchable elements, the output is as
+ expected:
+ 
+ 1: a 
+ 2: a 
+ - ---------------- 
+ 1: a 
+ 2: b 
+ - ---------------- 
+ 1: a 
+ 2: c 
+ - ---------------- 
+ 
+ The infinite loop outputs as follows:
+ 
+ 1: a 
+ 2: a 
+ - ---------------- 
+ 1: a 
+ 2: b 
+ - ---------------- 
+ 1: a 
+ 2: a 
+ - ---------------- 
+ 1: a 
+ 2: b 
+ - ---------------- 
+ 1: a 
+ 2: a 
+ - ----------------
+ <and so on>