Skip to content

Commit 1d1ccb0

Browse files
authored
Fixes for #420: Wrap unexpected IOOBE (#421)
1 parent 1f76529 commit 1d1ccb0

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ public JsonToken nextToken() throws IOException
550550
type = _reader.next();
551551
} catch (IonException e) {
552552
_wrapError(e.getMessage(), e);
553+
554+
// [dataformats-binary#420]: IonJava leaks IOOBEs so:
555+
} catch (IndexOutOfBoundsException e) {
556+
_wrapError(String.format("Corrupt content to decode; underlying failure: (%s) %s",
557+
e.getClass().getName(), e.getMessage()),
558+
e);
553559
}
554560
if (type == null) {
555561
if (_parsingContext.inRoot()) { // EOF?
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.InputStream;
4+
5+
import org.hamcrest.Matchers;
6+
import org.junit.Test;
7+
8+
import com.fasterxml.jackson.core.exc.StreamReadException;
9+
import com.fasterxml.jackson.dataformat.ion.*;
10+
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
import static org.junit.Assert.fail;
13+
14+
// [dataformats-binary#420]
15+
public class Fuzz420_65062_65083IOOBETest
16+
{
17+
@Test
18+
public void testFuzz6506265083IOOBE() throws Exception {
19+
IonFactory f = IonFactory
20+
.builderForTextualWriters()
21+
.enable(IonParser.Feature.USE_NATIVE_TYPE_ID)
22+
.build();
23+
IonObjectMapper mapper = IonObjectMapper.builder(f).build();
24+
try (InputStream in = getClass().getResourceAsStream("/data/fuzz-420.ion")) {
25+
mapper.readTree(in);
26+
fail("Should not pass (invalid content)");
27+
} catch (StreamReadException e) {
28+
assertThat(e.getMessage(), Matchers.containsString("Corrupt content to decode"));
29+
}
30+
}
31+
}
43 Bytes
Binary file not shown.

release-notes/CREDITS-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,5 @@ Arthur Chan (@arthurscchan)
285285
* Contributed #417: (ion) `IonReader` classes contain assert statement which could throw
286286
unexpected `AssertionError`
287287
(2.17.0)
288+
* Contributed #420: (ion) `IndexOutOfBoundsException` thrown by `IonReader` implementations
289+
(2.17.0)

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Active maintainers:
1919
#417: (ion) `IonReader` classes contain assert statement which could throw
2020
unexpected `AssertionError`
2121
(contributed by Arthur C)
22+
#420: (ion) `IndexOutOfBoundsException` thrown by `IonReader` implementations
23+
are not handled
24+
(contributed by Arthur C)
2225
-(ion) Update `com.amazon.ion:ion-java` to 1.11.0 (from 1.10.5)
2326

2427
2.16.0 (15-Nov-2023)

0 commit comments

Comments
 (0)