# HG changeset patch # User igerasim # Date 1558579319 25200 # Node ID 2ffbbd3c662ce0a0e81b91a299d1dd66c4ca9b8b # Parent 1b4ab3ebc51bdf7a08439e2b35246cd90c1240ea 8222684: Better support for patterns 8223163: Better pattern recognition Reviewed-by: ahgross, bchristi, jeff, rhalade, rriggs, smarks diff -r 1b4ab3ebc51b -r 2ffbbd3c662c src/java.base/share/classes/java/util/regex/Pattern.java --- a/src/java.base/share/classes/java/util/regex/Pattern.java Wed May 22 13:31:42 2019 -0400 +++ b/src/java.base/share/classes/java/util/regex/Pattern.java Wed May 22 19:41:59 2019 -0700 @@ -1427,7 +1427,11 @@ localTCNCount = 0; if (!pattern.isEmpty()) { - compile(); + try { + compile(); + } catch (StackOverflowError soe) { + throw error("Stack overflow during pattern compilation"); + } } else { root = new Start(lastAccept); matchRoot = lastAccept; @@ -1965,6 +1969,10 @@ int ch = temp[cursor++]; while (ch != 0 && !isLineSeparator(ch)) ch = temp[cursor++]; + if (ch == 0 && cursor > patternLength) { + cursor = patternLength; + ch = temp[cursor++]; + } return ch; } @@ -1975,6 +1983,10 @@ int ch = temp[++cursor]; while (ch != 0 && !isLineSeparator(ch)) ch = temp[++cursor]; + if (ch == 0 && cursor > patternLength) { + cursor = patternLength; + ch = temp[cursor]; + } return ch; } @@ -3415,9 +3427,10 @@ private int N() { if (read() == '{') { int i = cursor; - while (cursor < patternLength && read() != '}') {} - if (cursor > patternLength) - throw error("Unclosed character name escape sequence"); + while (read() != '}') { + if (cursor >= patternLength) + throw error("Unclosed character name escape sequence"); + } String name = new String(temp, i, cursor - i - 1); try { return Character.codePointOf(name);