Skip to content

Commit

Permalink
Fix OSS-Fuzz reported issue with SmileParser.getTextLength(), NPE (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Dec 15, 2023
1 parent 896dd7f commit b982f07
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,10 @@ public int getTextLength() throws IOException
|| (_currToken == JsonToken.VALUE_NUMBER_FLOAT)) {
return getNumberValue().toString().length();
}
return _currToken.asCharArray().length;
final char[] ch = _currToken.asCharArray();
if (ch != null) {
return ch.length;
}
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public char[] getTextCharacters() throws IOException {

@Override
public int getTextLength() throws IOException {
return getText().length();
String str = getText();
return (str == null) ? 0 : str.length();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,13 +1373,15 @@ public int getTextLength() throws IOException
return _textBuffer.size();
case FIELD_NAME:
return _parsingContext.getCurrentName().length();
// fall through
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return getNumberValue().toString().length();

default:
return _currToken.asCharArray().length;
// fall through
}
final char[] ch = _currToken.asCharArray();
if (ch != null) {
return ch.length;
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,10 @@ public int getTextLength() throws IOException
// TODO: optimize
return getNumberValue().toString().length();
}
return _currToken.asCharArray().length;
final char[] ch = _currToken.asCharArray();
if (ch != null) {
return ch.length;
}
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ public int getTextLength() throws IOException
case JsonTokenId.ID_NOT_AVAILABLE:
return 0; // or throw exception?
default:
return _currToken.asCharArray().length;
final char[] ch = _currToken.asCharArray();
if (ch != null) {
return ch.length;
}
return 0;
}
}

Expand Down

0 comments on commit b982f07

Please sign in to comment.