File tree 4 files changed +41
-12
lines changed
main/java/com/fasterxml/jackson/dataformat/ion
test/java/com/fasterxml/jackson/dataformat/ion/fuzz
4 files changed +41
-12
lines changed Original file line number Diff line number Diff line change @@ -593,8 +593,7 @@ public JsonToken nextToken() throws IOException
593
593
} catch (IonException e ) {
594
594
return _reportCorruptContent (e );
595
595
596
- // } catch (AssertionError | IndexOutOfBoundsException | NullPointerException e) {
597
- } catch (AssertionError | IndexOutOfBoundsException e ) {
596
+ } catch (AssertionError | IndexOutOfBoundsException | NullPointerException e ) {
598
597
// [dataformats-binary#420]: IonJava leaks IOOBEs, catch
599
598
// [dataformats-binary#432]: AssertionError if we're trying to get the text
600
599
// with a symbol id less than or equals to 0.
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 = FuzzTestUtil .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 = FuzzTestUtil .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 6
6
import org .junit .Test ;
7
7
8
8
import com .fasterxml .jackson .core .JsonParser ;
9
- import com .fasterxml .jackson .core .JsonToken ;
10
9
import com .fasterxml .jackson .core .exc .StreamReadException ;
11
10
import com .fasterxml .jackson .databind .ObjectMapper ;
12
11
import com .fasterxml .jackson .dataformat .ion .*;
13
12
14
13
import static org .hamcrest .MatcherAssert .assertThat ;
15
- import static org .junit .Assert .assertEquals ;
16
14
import static org .junit .Assert .fail ;
17
15
18
16
// [dataformats-binary#437]
@@ -21,10 +19,11 @@ public class Fuzz437_65452_NPETest
21
19
private final ObjectMapper ION_MAPPER = new IonObjectMapper ();
22
20
23
21
@ Test
24
- public void testFuzz65452Eof () throws Exception {
25
- try (InputStream in = getClass ().getResourceAsStream ("/data/fuzz-65452.ion" )) {
22
+ public void testFuzz65452NPE () throws Exception {
23
+ final byte [] doc = FuzzTestUtil .readResource ("/data/fuzz-65452.ion" );
24
+ try (InputStream in = new ByteArrayInputStream (doc )) {
26
25
try (JsonParser p = ION_MAPPER .createParser (in )) {
27
- assertEquals ( JsonToken . VALUE_FALSE , p .nextToken () );
26
+ p .nextToken ();
28
27
}
29
28
fail ("Should not pass (invalid content)" );
30
29
} catch (StreamReadException e ) {
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 FuzzTestUtil
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 = FuzzTestUtil .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
+ }
You can’t perform that action at this time.
0 commit comments