From 4c47b7503a363566607c0c3d4493e9c3203847ca Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Wed, 27 Dec 2023 13:21:11 +0000 Subject: [PATCH] Wrap the method call with try catch block Signed-off-by: Arthur Chan --- .../jackson/dataformat/ion/IonParser.java | 7 +- .../ion/fuzz/Fuzz434_65268_65274_NPETest.java | 60 ++++++++++++++++++ .../ion/fuzz/Fuzz434_65268_NPETest.java | 37 ----------- ion/src/test/resources/data/fuzz-65274.ion | Bin 0 -> 5214 bytes 4 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_65274_NPETest.java delete mode 100644 ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_NPETest.java create mode 100644 ion/src/test/resources/data/fuzz-65274.ion 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 0000000000000000000000000000000000000000..5e6ca06fd7e9593ff4e4b4c9c67c1c54dd911892 GIT binary patch literal 5214 zcmeHK&1(}u6raUN{{aP0LMU#qN)WOQ6^WkoA{KK~h=&C=G))@2G3qH-1=05Ao<#5@ zNCoS~lj6-H!IL*ZuR{NUP_XaK=iAL>9cpT*?So|B%)EW`zINvKet7Ixf671082j8W z6rxfexEuY#0;j7vzZP?P{z5#}|FU8p#Wjn}8ei5zQg~Ip6vt$#z-P%CjPpQRc$7dw zNJ|q%Vv~?BjZ&iDlLCyoWATj38|zOS_h(3qvi% z2_mAGGT-m{K~U=4jX)=3^YaaMld;a`+REnodO~4p-~}hqAZbKTbJRlXi5}Weq+UcO5jP30iGZ+&8+1lZXS`zD?)%Gn9bYBc;F^pY0$PbsHf9ACM!`@< z$kIVIm~yhEhv!25EyvFktNRX|Q1u2ZsR$)XGm&@=1Z-RGydnm+OXF3tW6>awHVG2T za;Vn`?}ZPFi9Uxz8((xk-!$OScew-Rw1LMox?TjKouX^eTL7F^;MO}Vw;Tt=1|5j9 zf2vMv+QDOGh|P1D69xmL^I-+u&^6-DElUT)1pHW}#;4EA5;yex}q3NH>KnTW@T)ufV4aIZ^J;X7}Sf z;9G+d5BV(ggq`j={CtYdaH(Fr*zUIY89