File tree 6 files changed +72
-7
lines changed
main/java/com/fasterxml/jackson/dataformat/ion
java/com/fasterxml/jackson/dataformat/ion/fuzz
6 files changed +72
-7
lines changed Original file line number Diff line number Diff line change @@ -593,8 +593,8 @@ public JsonToken nextToken() throws IOException
593
593
} catch (IonException e ) {
594
594
return _reportCorruptContent (e );
595
595
596
- } catch (IndexOutOfBoundsException | AssertionError e ) {
597
- // [dataformats-binary#420]: IonJava leaks IOOBEs so:
596
+ } catch (AssertionError | IndexOutOfBoundsException | NullPointerException e ) {
597
+ // [dataformats-binary#420]: IonJava leaks IOOBEs, catch
598
598
// [dataformats-binary#432]: AssertionError if we're trying to get the text
599
599
// with a symbol id less than or equals to 0.
600
600
return _reportCorruptContent (e );
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ public class Fuzz434_65268_65274_NPETest
24
24
// Test that used to fail on "getNumberType()" for `JsonToken.VALUE_NULL`
25
25
@ Test
26
26
public void testFuzz65268 () throws Exception {
27
- try (InputStream in = getClass ().getResourceAsStream ("/data/fuzz-65268.ion" )) {
27
+ final byte [] doc = IonFuzzTestUtil .readResource ("/data/fuzz-65268.ion" );
28
+ try (InputStream in = new ByteArrayInputStream (doc )) {
28
29
try (JsonParser p = ION_MAPPER .createParser (in )) {
29
30
assertEquals (JsonToken .VALUE_STRING , p .nextToken ());
30
31
p .getText ();
@@ -37,10 +38,9 @@ public void testFuzz65268() throws Exception {
37
38
38
39
@ Test
39
40
public void testFuzz65274Malformed () throws Exception {
40
- try (InputStream in = getClass ().getResourceAsStream ("/data/fuzz-65274.ion" )) {
41
- byte [] invalid = new byte [in .available ()];
42
- new DataInputStream (in ).readFully (invalid );
43
- ION_MAPPER .readTree (new ByteArrayInputStream (invalid ));
41
+ final byte [] doc = IonFuzzTestUtil .readResource ("/data/fuzz-65274.ion" );
42
+ try {
43
+ ION_MAPPER .readTree (new ByteArrayInputStream (doc ));
44
44
fail ("Should not pass (invalid content)" );
45
45
} catch (StreamReadException e ) {
46
46
assertThat (e .getMessage (), Matchers .containsString ("Corrupt content to decode" ));
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .dataformat .ion .fuzz ;
2
+
3
+ import java .io .*;
4
+
5
+ import org .hamcrest .Matchers ;
6
+ import org .junit .Test ;
7
+
8
+ import com .fasterxml .jackson .core .JsonParser ;
9
+ import com .fasterxml .jackson .core .exc .StreamReadException ;
10
+ import com .fasterxml .jackson .databind .ObjectMapper ;
11
+ import com .fasterxml .jackson .dataformat .ion .*;
12
+
13
+ import static org .hamcrest .MatcherAssert .assertThat ;
14
+ import static org .junit .Assert .fail ;
15
+
16
+ // [dataformats-binary#437]
17
+ public class Fuzz437_65452_NPETest
18
+ {
19
+ private final ObjectMapper ION_MAPPER = new IonObjectMapper ();
20
+
21
+ @ Test
22
+ public void testFuzz65452NPE () throws Exception {
23
+ final byte [] doc = IonFuzzTestUtil .readResource ("/data/fuzz-65452.ion" );
24
+ try (InputStream in = new ByteArrayInputStream (doc )) {
25
+ try (JsonParser p = ION_MAPPER .createParser (in )) {
26
+ p .nextToken ();
27
+ }
28
+ fail ("Should not pass (invalid content)" );
29
+ } catch (StreamReadException e ) {
30
+ assertThat (e .getMessage (), Matchers .containsString ("Corrupt content to decode" ));
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ package com .fasterxml .jackson .dataformat .ion .fuzz ;
2
+
3
+ import java .io .ByteArrayOutputStream ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStream ;
6
+
7
+ public class IonFuzzTestUtil
8
+ {
9
+ public static byte [] readResource (String ref )
10
+ {
11
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
12
+ final byte [] buf = new byte [4000 ];
13
+
14
+ InputStream in = IonFuzzTestUtil .class .getResourceAsStream (ref );
15
+ if (in != null ) {
16
+ try {
17
+ int len ;
18
+ while ((len = in .read (buf )) > 0 ) {
19
+ bytes .write (buf , 0 , len );
20
+ }
21
+ in .close ();
22
+ } catch (IOException e ) {
23
+ throw new RuntimeException ("Failed to read resource '" +ref +"': " +e );
24
+ }
25
+ }
26
+ if (bytes .size () == 0 ) {
27
+ throw new IllegalArgumentException ("Failed to read resource '" +ref +"': empty resource?" );
28
+ }
29
+ return bytes .toByteArray ();
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ Active maintainers:
30
30
(fix contributed by Arthur C )
31
31
#434 (ion) Unexpected `NullPointerException` thrown from `IonParser::getNumberType()`
32
32
(fix contributed by Arthur C )
33
+ #437 (ion) `IonReader.next()` throws NPEs for some invalid content
33
34
- (ion ) Update `com .amazon .ion :ion - java ` to 1.11 .0 (from 1.10 .5 )
34
35
35
36
2.16 .1 (24 - Dec - 2023 )
You can’t perform that action at this time.
0 commit comments