Skip to content

Commit

Permalink
Wraps unexpected NullPointerException
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Dec 5, 2023
1 parent 769a4c4 commit 30414de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,10 @@ public Object getNumberValueDeferred() throws IOException {
// 01-Feb-2023, tatu: ParserBase implementation does not quite work
// due to refactoring. So let's try to cobble something together

if (_cleanedTextValue == null) {
_reportError("Invalid value. Text value is null after cleaning.");
}

if (_currToken == JsonToken.VALUE_NUMBER_INT) {
// For integrals, use eager decoding for all ints, longs (and
// some cheaper BigIntegers)
Expand Down Expand Up @@ -1042,6 +1046,11 @@ public Object getNumberValueDeferred() throws IOException {
@Override
protected void _parseNumericValue(int expType) throws IOException
{

if (_cleanedTextValue == null) {
_reportError("Invalid value. Text value is null after cleaning.");
}

// Int or float?
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
int len = _cleanedTextValue.length();
Expand Down Expand Up @@ -1124,6 +1133,10 @@ protected void _parseNumericValue(int expType) throws IOException
@Override
protected int _parseIntValue() throws IOException
{
if (_cleanedTextValue == null) {
_reportError("Invalid value. Text value is null after cleaning.");
}

if (_currToken == JsonToken.VALUE_NUMBER_INT) {
int len = _cleanedTextValue.length();
if (_numberNegative) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fasterxml.jackson.dataformat.yaml.deser;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -85,4 +87,25 @@ public void testNumberDecoding61823() throws Exception
verifyException(e, "Invalid number");
}
}

// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64662
public void testNullPointerException64662() throws Exception
{
try {
YAML_MAPPER.readValue(" :: ! 0000000000000000000000000000", ModelContainer64662.class);
fail("Should not pass");
} catch (JacksonException e) {
verifyException(e, "Invalid value. Text value is null after cleaning.");
}
}

private static final class ModelContainer64662
{
public String string;

@JsonCreator
public ModelContainer64662(@JsonProperty(value = "string") String string) {
this.string = string;
}
}
}

0 comments on commit 30414de

Please sign in to comment.