Skip to content

Commit

Permalink
Fixes for FasterXML#420: Wrap unexpected IOOBE
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Dec 15, 2023
1 parent 207adca commit 82b2ce3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -614,7 +636,7 @@ public JsonParser skipChildren() throws IOException
*****************************************************************
* Internal helper methods
*****************************************************************
*/
*/

protected JsonToken _tokenFromType(IonType type)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
Binary file added ion/tc1
Binary file not shown.

0 comments on commit 82b2ce3

Please sign in to comment.