Skip to content

Commit

Permalink
Fix NullPointerException in Parser#factor (#149)
Browse files Browse the repository at this point in the history
The corresponding Go implementation relies on len(nilArray) being zero.

This issue was identified by the OSS-Fuzz integration effort described
in #135.
  • Loading branch information
sjamesr authored Jun 27, 2022
1 parent a594ae7 commit a664824
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions java/com/google/re2j/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@ && isCharClass(first.subs[0])))) {
for (int j = start + 1; j < i; j++) {
Regexp subMax = array[s + max], subJ = array[s + j];
if (subMax.op.ordinal() < subJ.op.ordinal()
|| (subMax.op == subJ.op && subMax.runes.length < subJ.runes.length)) {
|| (subMax.op == subJ.op
&& (subMax.runes != null ? subMax.runes.length : 0)
< (subJ.runes != null ? subJ.runes.length : 0))) {
max = j;
}
}
Expand Down Expand Up @@ -782,7 +784,7 @@ public String toString() {
}

/**
* Parse regular expression pattern {@var pattern} with mode flags {@var flags}.
* Parse regular expression pattern {@code pattern} with mode flags {@code flags}.
*/
static Regexp parse(String pattern, int flags) throws PatternSyntaxException {
return new Parser(pattern, flags).parseInternal();
Expand Down
1 change: 1 addition & 0 deletions javatests/com/google/re2j/RE2CompileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static String[][] testData() {
{"[abc]", null},
{"[^1234]", null},
{"[^\n]", null},
{"..|.#|..", null},
{"\\!\\\\", null},
{"abc]", null}, // Matches the closing bracket literally.
{"a??", null},
Expand Down

0 comments on commit a664824

Please sign in to comment.