Skip to content

Commit f482d8d

Browse files
committed
Fix NullPointerException in Parser#factor
The corresponding Go implementation relies on len(nilArray) being zero. This issue was identified by the OSS-Fuzz integration effort described in #135.
1 parent 541d02f commit f482d8d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

java/com/google/re2j/Parser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ && isCharClass(first.subs[0])))) {
550550
for (int j = start + 1; j < i; j++) {
551551
Regexp subMax = array[s + max], subJ = array[s + j];
552552
if (subMax.op.ordinal() < subJ.op.ordinal()
553-
|| (subMax.op == subJ.op && subMax.runes.length < subJ.runes.length)) {
553+
|| (subMax.op == subJ.op
554+
&& (subMax.runes != null ? subMax.runes.length : 0)
555+
< (subJ.runes != null ? subJ.runes.length : 0))) {
554556
max = j;
555557
}
556558
}
@@ -782,7 +784,7 @@ public String toString() {
782784
}
783785

784786
/**
785-
* Parse regular expression pattern {@var pattern} with mode flags {@var flags}.
787+
* Parse regular expression pattern {@code pattern} with mode flags {@code flags}.
786788
*/
787789
static Regexp parse(String pattern, int flags) throws PatternSyntaxException {
788790
return new Parser(pattern, flags).parseInternal();

javatests/com/google/re2j/RE2CompileTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static String[][] testData() {
3636
{"[abc]", null},
3737
{"[^1234]", null},
3838
{"[^\n]", null},
39+
{"..|.#|..", null},
3940
{"\\!\\\\", null},
4041
{"abc]", null}, // Matches the closing bracket literally.
4142
{"a??", null},

0 commit comments

Comments
 (0)