-
Bug
-
Resolution: Unresolved
-
P3
-
17
j.u.regex.Pattern.compile(pattern) studies the pattern to determine its minimum/maximum length.
These values can become invalid due to overflow, which can result in misleading exception thrown during the match operations.
One example:
import java.util.regex.*;
public class T {
public static void main(String[] args) throws Throwable {
String pat = "\uD800\uDFFFa{2147483647,}b{2147483647,}";
Pattern p = Pattern.compile(pat);
Matcher m = p.matcher("ab");
System.out.println(m.find());
}
}
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
at java.base/java.lang.String.charAt(String.java:711)
at java.base/java.util.regex.Pattern$StartS.match(Pattern.java:3670)
at java.base/java.util.regex.Matcher.search(Matcher.java:1729)
at java.base/java.util.regex.Matcher.find(Matcher.java:746)
at T.main(T.java:7)
These values can become invalid due to overflow, which can result in misleading exception thrown during the match operations.
One example:
import java.util.regex.*;
public class T {
public static void main(String[] args) throws Throwable {
String pat = "\uD800\uDFFFa{2147483647,}b{2147483647,}";
Pattern p = Pattern.compile(pat);
Matcher m = p.matcher("ab");
System.out.println(m.find());
}
}
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
at java.base/java.lang.String.charAt(String.java:711)
at java.base/java.util.regex.Pattern$StartS.match(Pattern.java:3670)
at java.base/java.util.regex.Matcher.search(Matcher.java:1729)
at java.base/java.util.regex.Matcher.find(Matcher.java:746)
at T.main(T.java:7)