Skip to content

Commit 18108a4

Browse files
arthurscchancowtowncoder
authored andcommitted
Fixes for issue #445: Wraps unexpected NullPointerException (#446)
1 parent 8e47f98 commit 18108a4

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,18 @@ public Object getNumberValueDeferred() throws IOException {
10131013
// due to refactoring. So let's try to cobble something together
10141014

10151015
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
1016-
// For integrals, use eager decoding for all ints, longs (and
1017-
// some cheaper BigIntegers)
1018-
if (_cleanedTextValue.length() <= 18) {
1019-
return getNumberValue();
1016+
// We might already have suitable value?
1017+
if ((_numTypesValid & NR_INT) != 0) {
1018+
return _numberInt;
1019+
}
1020+
if ((_numTypesValid & NR_LONG) != 0) {
1021+
return _numberLong;
1022+
}
1023+
if ((_numTypesValid & NR_BIGINT) != 0) {
1024+
return _getBigInteger();
1025+
}
1026+
if (_cleanedTextValue == null) {
1027+
_reportError("Internal number decoding error: `_cleanedTextValue` null when nothing decoded for `JsonToken.VALUE_NUMBER_INT`");
10201028
}
10211029
return _cleanedTextValue;
10221030
}

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/FuzzYAMLReadTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.jackson.dataformat.yaml.deser;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
35
import com.fasterxml.jackson.core.JacksonException;
46
import com.fasterxml.jackson.core.JsonToken;
57
import com.fasterxml.jackson.databind.JsonNode;
@@ -85,4 +87,28 @@ public void testNumberDecoding61823() throws Exception
8587
verifyException(e, "Invalid number");
8688
}
8789
}
90+
91+
// [dataformats-text#445]: NPE
92+
static class ModelContainer445
93+
{
94+
public String string;
95+
96+
@JsonCreator
97+
public ModelContainer445(@JsonProperty(value = "string") String string) {
98+
this.string = string;
99+
}
100+
}
101+
102+
// [dataformats-text#445]: NPE
103+
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64662
104+
public void testNullPointerException445_64662() throws Exception
105+
{
106+
// Content itself odd, generated by Fuzz; but needs to trigger buffering to work
107+
try {
108+
YAML_MAPPER.readValue(" :: ! 0000000000000000000000000000", ModelContainer445.class);
109+
fail("Should not pass");
110+
} catch (JacksonException e) {
111+
verifyException(e, "Unrecognized field");
112+
}
113+
}
88114
}

0 commit comments

Comments
 (0)