diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java index e9c6c3894..e4eb7ab12 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java @@ -397,7 +397,12 @@ public NumberType getNumberType() throws IOException //Ion decimals can be arbitrary precision, need to read as big decimal return NumberType.BIG_DECIMAL; case INT: - IntegerSize size = _reader.getIntegerSize(); + IntegerSize size = null; + try { + size = _reader.getIntegerSize(); + } catch (NullPointerException e) { + // Possible exception + } if (size == null) { _reportError("Current token (%s) not integer", _currToken); } diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_65274_NPETest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_65274_NPETest.java new file mode 100644 index 000000000..950e8084c --- /dev/null +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_65274_NPETest.java @@ -0,0 +1,60 @@ +package com.fasterxml.jackson.dataformat.ion.fuzz; + +import java.io.InputStream; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.ion.*; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.*; +import java.nio.file.*; + +// [dataformats-binary#434 +public class Fuzz434_65268_65274_NPETest +{ + @Test + public void testFuzz65268() throws Exception { + final IonFactory factory = + IonFactory.builderForTextualWriters().build(); + try (InputStream in = getClass().getResourceAsStream("/data/fuzz-65268.ion")) { + try (JsonParser p = factory.createParser(in)) { + p.nextToken(); + p.getText(); + p.nextTextValue(); + p.getNumberType(); + } + fail("Should not pass (invalid content)"); + } catch (StreamReadException e) { + assertThat(e.getMessage(), Matchers.containsString("not integer")); + } + } + + @Test + public void testFuzz65274() throws Exception { + final ObjectMapper MAPPER = + IonObjectMapper.builder( + IonFactory.builderForBinaryWriters() + .enable(IonParser.Feature.USE_NATIVE_TYPE_ID) + .build()) + .build(); + + try (InputStream in = getClass().getResourceAsStream("/data/fuzz-65274.ion")) { + byte[] invalid = in.readAllBytes(); + try (JsonParser p = MAPPER.getFactory().createParser(new ByteArrayInputStream(invalid))) { + MAPPER.readTree(p); + } + fail("Should not pass (invalid content)"); + } catch (StreamReadException e) { + assertThat(e.getMessage(), Matchers.containsString("not integer")); + } + } +} diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_NPETest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_NPETest.java deleted file mode 100644 index 12606799b..000000000 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_NPETest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fasterxml.jackson.dataformat.ion.fuzz; - -import java.io.InputStream; - -import org.hamcrest.Matchers; -import org.junit.Test; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.exc.StreamReadException; -import com.fasterxml.jackson.dataformat.ion.*; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -// [dataformats-binary#434 -public class Fuzz434_65268_NPETest -{ - private final IonFactory factory = - IonFactory.builderForTextualWriters().build(); - - @Test - public void testFuzz65268() throws Exception { - try (InputStream in = getClass().getResourceAsStream("/data/fuzz-65268.ion")) { - try (JsonParser p = factory.createParser(in)) { - p.nextToken(); - p.getText(); - p.nextTextValue(); - p.getNumberType(); - } - fail("Should not pass (invalid content)"); - } catch (StreamReadException e) { - assertThat(e.getMessage(), Matchers.containsString("not integer")); - } - } -} diff --git a/ion/src/test/resources/data/fuzz-65274.ion b/ion/src/test/resources/data/fuzz-65274.ion new file mode 100644 index 000000000..5e6ca06fd Binary files /dev/null and b/ion/src/test/resources/data/fuzz-65274.ion differ