Skip to content

Commit

Permalink
Fixes for issue #445: Wraps unexpected NullPointerException (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurscchan authored and cowtowncoder committed Dec 12, 2023
1 parent 8e47f98 commit 18108a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,18 @@ public Object getNumberValueDeferred() throws IOException {
// due to refactoring. So let's try to cobble something together

if (_currToken == JsonToken.VALUE_NUMBER_INT) {
// For integrals, use eager decoding for all ints, longs (and
// some cheaper BigIntegers)
if (_cleanedTextValue.length() <= 18) {
return getNumberValue();
// We might already have suitable value?
if ((_numTypesValid & NR_INT) != 0) {
return _numberInt;
}
if ((_numTypesValid & NR_LONG) != 0) {
return _numberLong;
}
if ((_numTypesValid & NR_BIGINT) != 0) {
return _getBigInteger();
}
if (_cleanedTextValue == null) {
_reportError("Internal number decoding error: `_cleanedTextValue` null when nothing decoded for `JsonToken.VALUE_NUMBER_INT`");
}
return _cleanedTextValue;
}
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,28 @@ public void testNumberDecoding61823() throws Exception
verifyException(e, "Invalid number");
}
}

// [dataformats-text#445]: NPE
static class ModelContainer445
{
public String string;

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

// [dataformats-text#445]: NPE
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64662
public void testNullPointerException445_64662() throws Exception
{
// Content itself odd, generated by Fuzz; but needs to trigger buffering to work
try {
YAML_MAPPER.readValue(" :: ! 0000000000000000000000000000", ModelContainer445.class);
fail("Should not pass");
} catch (JacksonException e) {
verifyException(e, "Unrecognized field");
}
}
}

0 comments on commit 18108a4

Please sign in to comment.