From fb855c0568b781121340225726285c8e47844c5f Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 26 Jan 2024 21:57:38 -0800 Subject: [PATCH] Add not-failing test that tries to reproduce #473: has the data but call sequence not same as OSS-Fuzzer (#474) --- .../IonFuzz_473_66131_AIOOBE_Test.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonFuzz_473_66131_AIOOBE_Test.java diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonFuzz_473_66131_AIOOBE_Test.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonFuzz_473_66131_AIOOBE_Test.java new file mode 100644 index 000000000..e721bdc02 --- /dev/null +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonFuzz_473_66131_AIOOBE_Test.java @@ -0,0 +1,33 @@ +package com.fasterxml.jackson.dataformat.ion.failing; + +import org.hamcrest.Matchers; +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.ion.*; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +//[dataformats-binary#473]: ArrayIndexOutOfBoundsException +//https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66131 +public class IonFuzz_473_66131_AIOOBE_Test +{ + private final ObjectMapper ION_MAPPER = new IonObjectMapper(); + + @Test + public void testFuzz66077_ArrayIndexOOBE() throws Exception { + final byte[] doc = { (byte) 0xe0, 0x01, 0x00, (byte) 0xea, (byte) 0xdc, (byte) 0x9a }; + try (JsonParser p = ION_MAPPER.createParser(doc)) { + assertEquals(JsonToken.START_OBJECT, p.nextToken()); + p.nextTextValue(); + fail("Should not pass (invalid content)"); + } catch (StreamReadException e) { + assertThat(e.getMessage(), Matchers.containsString("Corrupt content to decode")); + } + } +}