From 08b9c2b72300fde041423ca1ba51f130cdf3637d Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Tue, 5 Dec 2023 20:05:11 +0000 Subject: [PATCH] Wrap possible AssertionError from Ion class Signed-off-by: Arthur Chan --- .../jackson/dataformat/ion/IonParser.java | 5 +++- .../ion/fuzz/Fuzz64721InvalidIonTest.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz64721InvalidIonTest.java 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..93e0e0767 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 @@ -274,8 +274,11 @@ public String getText() throws IOException try { // 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 + // AssertionError if we're trying to get the text with a symbol + // id less than or equals to 0. return _reader.stringValue(); - } catch (UnknownSymbolException e) { + } catch (UnknownSymbolException | AssertionError e) { throw _constructError(e.getMessage(), e); } case VALUE_NUMBER_INT: diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz64721InvalidIonTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz64721InvalidIonTest.java new file mode 100644 index 000000000..ac8558910 --- /dev/null +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/Fuzz64721InvalidIonTest.java @@ -0,0 +1,27 @@ +package com.fasterxml.jackson.dataformat.ion.fuzz; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.dataformat.ion.*; + +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Test; + +@SuppressWarnings("resource") +public class Fuzz64721InvalidIonTest +{ + @Test(expected = JsonParseException.class) + public void testFuzz64721AssertionException() throws IOException { + IonFactory f = IonFactory + .builderForBinaryWriters() + .enable(IonParser.Feature.USE_NATIVE_TYPE_ID) + .build(); + IonObjectMapper mapper = IonObjectMapper.builder(f).build(); + mapper.readValue("$0/", EnumFuzz.class); + } + + private static enum EnumFuzz { + A, B, C, D, E; + } +}