Skip to content

Commit 9cfab17

Browse files
committed
Fix #437
1 parent b5b3a3a commit 9cfab17

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ public JsonToken nextToken() throws IOException
593593
} catch (IonException e) {
594594
return _reportCorruptContent(e);
595595

596-
// } catch (AssertionError | IndexOutOfBoundsException | NullPointerException e) {
597-
} catch (AssertionError | IndexOutOfBoundsException e) {
596+
} catch (AssertionError | IndexOutOfBoundsException | NullPointerException e) {
598597
// [dataformats-binary#420]: IonJava leaks IOOBEs, catch
599598
// [dataformats-binary#432]: AssertionError if we're trying to get the text
600599
// with a symbol id less than or equals to 0.

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz434_65268_65274_NPETest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class Fuzz434_65268_65274_NPETest
2424
// Test that used to fail on "getNumberType()" for `JsonToken.VALUE_NULL`
2525
@Test
2626
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)) {
2829
try (JsonParser p = ION_MAPPER.createParser(in)) {
2930
assertEquals(JsonToken.VALUE_STRING, p.nextToken());
3031
p.getText();
@@ -37,10 +38,9 @@ public void testFuzz65268() throws Exception {
3738

3839
@Test
3940
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));
4444
fail("Should not pass (invalid content)");
4545
} catch (StreamReadException e) {
4646
assertThat(e.getMessage(), Matchers.containsString("Corrupt content to decode"));

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz437_65452_NPETest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
import org.junit.Test;
77

88
import com.fasterxml.jackson.core.JsonParser;
9-
import com.fasterxml.jackson.core.JsonToken;
109
import com.fasterxml.jackson.core.exc.StreamReadException;
1110
import com.fasterxml.jackson.databind.ObjectMapper;
1211
import com.fasterxml.jackson.dataformat.ion.*;
1312

1413
import static org.hamcrest.MatcherAssert.assertThat;
15-
import static org.junit.Assert.assertEquals;
1614
import static org.junit.Assert.fail;
1715

1816
// [dataformats-binary#437]
@@ -21,10 +19,11 @@ public class Fuzz437_65452_NPETest
2119
private final ObjectMapper ION_MAPPER = new IonObjectMapper();
2220

2321
@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)) {
2625
try (JsonParser p = ION_MAPPER.createParser(in)) {
27-
assertEquals(JsonToken.VALUE_FALSE, p.nextToken());
26+
p.nextToken();
2827
}
2928
fail("Should not pass (invalid content)");
3029
} catch (StreamReadException e) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

0 commit comments

Comments
 (0)