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 d4352a976..265f54720 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 @@ -269,14 +269,23 @@ public String getText() throws IOException if (_currToken != null) { // null only before/after document switch (_currToken) { case FIELD_NAME: - return getCurrentName(); + return currentName(); case VALUE_STRING: try { - // stringValue() will throw an UnknownSymbolException if we're - // trying to get the text for a symbol id that cannot be resolved. return _reader.stringValue(); } catch (UnknownSymbolException e) { + // stringValue() will throw an UnknownSymbolException if we're + // trying to get the text for a symbol id that cannot be resolved. + // stringValue() has an assert statement which could throw an throw _constructError(e.getMessage(), e); + } catch (AssertionError e) { + // AssertionError if we're trying to get the text with a symbol + // id less than or equals to 0. + String msg = e.getMessage(); + if (msg == null) { + msg = "UNKNOWN ROOT CAUSE"; + } + throw _constructError("Internal `IonReader` error: "+msg, e); } case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: @@ -487,24 +496,35 @@ public Object getTypeId() throws IOException { */ @Override - public JsonLocation getCurrentLocation() { + public JsonLocation currentLocation() { return JsonLocation.NA; } @Override - public String getCurrentName() throws IOException { - return _parsingContext.getCurrentName(); + public JsonLocation currentTokenLocation() { + return JsonLocation.NA; } + @Deprecated // since 2.17 @Override - public JsonStreamContext getParsingContext() { - return _parsingContext; - } + public JsonLocation getCurrentLocation() { return currentLocation(); } + @Deprecated // since 2.17 + @Override + public JsonLocation getTokenLocation() { return currentTokenLocation(); } @Override - public JsonLocation getTokenLocation() { - return JsonLocation.NA; + public String currentName() throws IOException { + return _parsingContext.getCurrentName(); + } + + @Deprecated // since 2.17 + @Override + public String getCurrentName() throws IOException { return currentName(); } + + @Override + public JsonStreamContext getParsingContext() { + return _parsingContext; } @Override @@ -529,6 +549,8 @@ public JsonToken nextToken() throws IOException type = _reader.next(); } catch (IonException e) { _wrapError(e.getMessage(), e); + } catch (IndexOutOfBoundsException e) { + _constructError(e.getMessage(), e); } if (type == null) { if (_parsingContext.inRoot()) { // EOF? @@ -614,7 +636,7 @@ public JsonParser skipChildren() throws IOException ***************************************************************** * Internal helper methods ***************************************************************** - */ + */ protected JsonToken _tokenFromType(IonType type) { diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz417_64721InvalidIonTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz417_64721InvalidIonTest.java new file mode 100644 index 000000000..b51e4a460 --- /dev/null +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz417_64721InvalidIonTest.java @@ -0,0 +1,33 @@ +package com.fasterxml.jackson.dataformat.ion.fuzz; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.dataformat.ion.*; + +// [dataformats-binary#417] +public class Fuzz417_64721InvalidIonTest +{ + enum EnumFuzz { + A, B, C, D, E; + } + + @Test + public void testFuzz64721AssertionException() throws Exception { + IonFactory f = IonFactory + .builderForBinaryWriters() + .enable(IonParser.Feature.USE_NATIVE_TYPE_ID) + .build(); + IonObjectMapper mapper = IonObjectMapper.builder(f).build(); + try { + mapper.readValue("$0/", EnumFuzz.class); + fail("Should not pass (invalid content)"); + } catch (StreamReadException e) { + assertThat(e.getMessage(), Matchers.containsString("Internal `IonReader` error")); + } + } +} diff --git a/ion/tc1 b/ion/tc1 new file mode 100644 index 000000000..72932169b Binary files /dev/null and b/ion/tc1 differ