Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OSS-Fuzz reported issue with SmileParser.getTextLength(), NPE #423

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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