From a781520b7318e2c0c3e79ed914d1b30889f87978 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Wed, 20 Dec 2023 18:38:55 +0800 Subject: [PATCH] jackson-dataformats-binary: Catch expected IonException (#11388) This PR catches an expected IonException from Ion-related parsers and also fixes some formating of fuzzers. This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65180 and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65181. Signed-off-by: Arthur Chan --- projects/jackson-dataformats-binary/IonGeneratorFuzzer.java | 2 ++ projects/jackson-dataformats-binary/IonParserFuzzer.java | 3 ++- projects/jackson-dataformats-binary/SerializerFuzzer.java | 6 +++++- .../jackson-dataformats-binary/SmileGeneratorFuzzer.java | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/projects/jackson-dataformats-binary/IonGeneratorFuzzer.java b/projects/jackson-dataformats-binary/IonGeneratorFuzzer.java index 5b65f26da6fc..2d4cbd2e0985 100644 --- a/projects/jackson-dataformats-binary/IonGeneratorFuzzer.java +++ b/projects/jackson-dataformats-binary/IonGeneratorFuzzer.java @@ -13,6 +13,7 @@ // limitations under the License. // /////////////////////////////////////////////////////////////////////////// +import com.amazon.ion.IonException; import com.code_intelligence.jazzer.api.FuzzedDataProvider; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.io.SerializedString; @@ -138,6 +139,7 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { } catch (IOException | IllegalArgumentException | IllegalStateException + | IonException | UnsupportedOperationException e) { // Known exception } diff --git a/projects/jackson-dataformats-binary/IonParserFuzzer.java b/projects/jackson-dataformats-binary/IonParserFuzzer.java index 9fbe715f96a7..b147e3c34115 100644 --- a/projects/jackson-dataformats-binary/IonParserFuzzer.java +++ b/projects/jackson-dataformats-binary/IonParserFuzzer.java @@ -13,6 +13,7 @@ // limitations under the License. // /////////////////////////////////////////////////////////////////////////// +import com.amazon.ion.IonException; import com.code_intelligence.jazzer.api.FuzzedDataProvider; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.dataformat.ion.IonFactory; @@ -121,7 +122,7 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { } parser.close(); - } catch (IOException | IllegalArgumentException | IllegalStateException e) { + } catch (IOException | IllegalArgumentException | IllegalStateException | IonException e) { // Known exception } } diff --git a/projects/jackson-dataformats-binary/SerializerFuzzer.java b/projects/jackson-dataformats-binary/SerializerFuzzer.java index e20e20d06002..bbfc53b3b9b6 100644 --- a/projects/jackson-dataformats-binary/SerializerFuzzer.java +++ b/projects/jackson-dataformats-binary/SerializerFuzzer.java @@ -13,6 +13,7 @@ // limitations under the License. // /////////////////////////////////////////////////////////////////////////// +import com.amazon.ion.IonException; import com.code_intelligence.jazzer.api.FuzzedDataProvider; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonRawValue; @@ -253,7 +254,10 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { writer.writeValueAsString(object); writer.writeValueAsBytes(object); - } catch (IOException | IllegalArgumentException | UnsupportedOperationException e) { + } catch (IOException + | IllegalArgumentException + | UnsupportedOperationException + | IonException e) { // Known exception } finally { try { diff --git a/projects/jackson-dataformats-binary/SmileGeneratorFuzzer.java b/projects/jackson-dataformats-binary/SmileGeneratorFuzzer.java index da1c784af3d0..6c7d4208ae06 100644 --- a/projects/jackson-dataformats-binary/SmileGeneratorFuzzer.java +++ b/projects/jackson-dataformats-binary/SmileGeneratorFuzzer.java @@ -46,7 +46,8 @@ public static void fuzzerTestOneInput(FuzzedDataProvider data) { } // Create and configure SmileGenerator - SmileGenerator generator = ((SmileMapper)mapper).getFactory().createGenerator(new ByteArrayOutputStream()); + SmileGenerator generator = + ((SmileMapper) mapper).getFactory().createGenerator(new ByteArrayOutputStream()); for (SmileGenerator.Feature feature : featureSet) { generator.configure(feature, data.consumeBoolean()); }