From 8428c9c9e257f7ada093ebb587282c25df6aa623 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 21:06:39 +0000 Subject: [PATCH] test: cargo-fuzz targets (parse_jcs, canon_roundtrip, cli_input) with RFC 8785 seed corpus and 60s CI smoke Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhUv8btVaxjhTHSUtk --- .github/workflows/fuzz.yml | 55 +++++ fuzz/.gitignore | 2 + fuzz/Cargo.lock | 221 ++++++++++++++++++ fuzz/Cargo.toml | 38 +++ fuzz/README.adoc | 27 +++ fuzz/corpus/canon_roundtrip/neg-duplicate-key | 1 + .../corpus/canon_roundtrip/neg-lone-surrogate | 1 + fuzz/corpus/canon_roundtrip/neg-overflow | 1 + fuzz/corpus/canon_roundtrip/neg-truncated | 1 + .../canon_roundtrip/neg-truncated-array | 1 + .../canon_roundtrip/rfc8785-3.2.3-key-order | 1 + .../canon_roundtrip/rfc8785-3.2.4-example | 1 + .../canon_roundtrip/rfc8785-appendix-b-01 | 1 + .../canon_roundtrip/rfc8785-appendix-b-02 | 1 + .../canon_roundtrip/rfc8785-appendix-b-03 | 1 + .../canon_roundtrip/rfc8785-appendix-b-04 | 1 + .../canon_roundtrip/rfc8785-appendix-b-05 | 1 + .../canon_roundtrip/rfc8785-appendix-b-06 | 1 + .../canon_roundtrip/rfc8785-appendix-b-07 | 1 + .../canon_roundtrip/rfc8785-appendix-b-08 | 1 + .../canon_roundtrip/rfc8785-appendix-b-09 | 1 + .../canon_roundtrip/rfc8785-appendix-b-10 | 1 + .../canon_roundtrip/rfc8785-appendix-b-11 | 1 + .../canon_roundtrip/rfc8785-appendix-b-12 | 1 + .../canon_roundtrip/rfc8785-appendix-b-13 | 1 + .../canon_roundtrip/rfc8785-appendix-b-14 | 1 + .../canon_roundtrip/rfc8785-appendix-b-15 | 1 + .../canon_roundtrip/rfc8785-appendix-b-16 | 1 + .../canon_roundtrip/rfc8785-appendix-b-17 | 1 + .../canon_roundtrip/rfc8785-appendix-b-18 | 1 + .../canon_roundtrip/rfc8785-appendix-b-19 | 1 + .../canon_roundtrip/rfc8785-appendix-b-20 | 1 + .../canon_roundtrip/rfc8785-appendix-b-21 | 1 + .../canon_roundtrip/rfc8785-appendix-b-22 | 1 + .../canon_roundtrip/rfc8785-appendix-b-23 | 1 + .../canon_roundtrip/rfc8785-appendix-b-24 | 1 + .../canon_roundtrip/rfc8785-appendix-b-25 | 1 + fuzz/corpus/cli_input/jsonld-good | 1 + fuzz/corpus/cli_input/neg-duplicate-key | 1 + fuzz/corpus/cli_input/neg-lone-surrogate | 1 + fuzz/corpus/cli_input/neg-overflow | 1 + fuzz/corpus/cli_input/neg-truncated | 1 + fuzz/corpus/cli_input/neg-truncated-array | 1 + fuzz/corpus/cli_input/records-good.jsonl | 2 + fuzz/corpus/cli_input/rfc8785-3.2.3-key-order | 1 + fuzz/corpus/cli_input/rfc8785-3.2.4-example | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-01 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-02 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-03 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-04 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-05 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-06 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-07 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-08 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-09 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-10 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-11 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-12 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-13 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-14 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-15 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-16 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-17 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-18 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-19 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-20 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-21 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-22 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-23 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-24 | 1 + fuzz/corpus/cli_input/rfc8785-appendix-b-25 | 1 + fuzz/corpus/parse_jcs/neg-duplicate-key | 1 + fuzz/corpus/parse_jcs/neg-lone-surrogate | 1 + fuzz/corpus/parse_jcs/neg-overflow | 1 + fuzz/corpus/parse_jcs/neg-truncated | 1 + fuzz/corpus/parse_jcs/neg-truncated-array | 1 + fuzz/corpus/parse_jcs/rfc8785-3.2.3-key-order | 1 + fuzz/corpus/parse_jcs/rfc8785-3.2.4-example | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-01 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-02 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-03 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-04 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-05 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-06 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-07 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-08 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-09 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-10 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-11 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-12 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-13 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-14 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-15 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-16 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-17 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-18 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-19 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-20 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-21 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-22 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-23 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-24 | 1 + fuzz/corpus/parse_jcs/rfc8785-appendix-b-25 | 1 + fuzz/fuzz_targets/canon_roundtrip.rs | 21 ++ fuzz/fuzz_targets/cli_input.rs | 43 ++++ fuzz/fuzz_targets/parse_jcs.rs | 16 ++ 106 files changed, 522 insertions(+) create mode 100644 .github/workflows/fuzz.yml create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.lock create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/README.adoc create mode 100644 fuzz/corpus/canon_roundtrip/neg-duplicate-key create mode 100644 fuzz/corpus/canon_roundtrip/neg-lone-surrogate create mode 100644 fuzz/corpus/canon_roundtrip/neg-overflow create mode 100644 fuzz/corpus/canon_roundtrip/neg-truncated create mode 100644 fuzz/corpus/canon_roundtrip/neg-truncated-array create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-3.2.3-key-order create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-3.2.4-example create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-01 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-02 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-03 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-04 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-05 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-06 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-07 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-08 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-09 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-10 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-11 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-12 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-13 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-14 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-15 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-16 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-17 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-18 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-19 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-20 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-21 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-22 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-23 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-24 create mode 100644 fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-25 create mode 100644 fuzz/corpus/cli_input/jsonld-good create mode 100644 fuzz/corpus/cli_input/neg-duplicate-key create mode 100644 fuzz/corpus/cli_input/neg-lone-surrogate create mode 100644 fuzz/corpus/cli_input/neg-overflow create mode 100644 fuzz/corpus/cli_input/neg-truncated create mode 100644 fuzz/corpus/cli_input/neg-truncated-array create mode 100644 fuzz/corpus/cli_input/records-good.jsonl create mode 100644 fuzz/corpus/cli_input/rfc8785-3.2.3-key-order create mode 100644 fuzz/corpus/cli_input/rfc8785-3.2.4-example create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-01 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-02 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-03 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-04 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-05 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-06 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-07 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-08 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-09 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-10 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-11 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-12 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-13 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-14 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-15 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-16 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-17 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-18 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-19 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-20 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-21 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-22 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-23 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-24 create mode 100644 fuzz/corpus/cli_input/rfc8785-appendix-b-25 create mode 100644 fuzz/corpus/parse_jcs/neg-duplicate-key create mode 100644 fuzz/corpus/parse_jcs/neg-lone-surrogate create mode 100644 fuzz/corpus/parse_jcs/neg-overflow create mode 100644 fuzz/corpus/parse_jcs/neg-truncated create mode 100644 fuzz/corpus/parse_jcs/neg-truncated-array create mode 100644 fuzz/corpus/parse_jcs/rfc8785-3.2.3-key-order create mode 100644 fuzz/corpus/parse_jcs/rfc8785-3.2.4-example create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-01 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-02 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-03 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-04 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-05 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-06 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-07 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-08 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-09 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-10 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-11 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-12 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-13 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-14 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-15 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-16 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-17 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-18 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-19 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-20 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-21 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-22 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-23 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-24 create mode 100644 fuzz/corpus/parse_jcs/rfc8785-appendix-b-25 create mode 100644 fuzz/fuzz_targets/canon_roundtrip.rs create mode 100644 fuzz/fuzz_targets/cli_input.rs create mode 100644 fuzz/fuzz_targets/parse_jcs.rs diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 0000000..d3b9e5b --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: MPL-2.0 +# KYAML content; GitHub requires the .yml extension. +{ + name: "Fuzz smoke", + on: { + pull_request: {}, + workflow_dispatch: {}, + }, + permissions: { + contents: "read", + }, + concurrency: { + group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}", + cancel-in-progress: true, + }, + jobs: { + fuzz: { + name: "Fuzz smoke (${{ matrix.target }})", + runs-on: "ubuntu-24.04", + timeout-minutes: 15, + strategy: { + fail-fast: false, + matrix: { + target: ["parse_jcs", "canon_roundtrip", "cli_input"], + }, + }, + steps: [ + { + uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1", # v7.0.1 + with: { + persist-credentials: false, + }, + }, + { + name: "Install pinned nightly and cargo-fuzz", + run: "set -euo pipefail\nrustup toolchain install nightly-2026-11-30 --profile minimal\ncargo install cargo-fuzz --locked --version 0.13.2", + }, + { + name: "Fuzz for 60 seconds from the committed seed corpus", + run: "set -euo pipefail\ncp -r \"fuzz/corpus/${{ matrix.target }}\" \"$RUNNER_TEMP/corpus\"\ncd fuzz\ncargo +nightly-2026-11-30 fuzz run \"${{ matrix.target }}\" \"$RUNNER_TEMP/corpus\" -- -max_total_time=60 -max_len=4096", + }, + { + name: "Keep any crashing input", + if: "failure()", + uses: "actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a", # v7.0.1 + with: { + name: "fuzz-crash-${{ matrix.target }}", + path: "fuzz/artifacts", + if-no-files-found: "ignore", + }, + }, + ], + }, + }, +} diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..35ae8a0 --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,2 @@ +target +artifacts diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock new file mode 100644 index 0000000..4dca906 --- /dev/null +++ b/fuzz/Cargo.lock @@ -0,0 +1,221 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "arbitrary" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed" + +[[package]] +name = "cc" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "find-msvc-tools" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8" + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "ijson-jcs" +version = "0.1.0" +dependencies = [ + "ryu-js", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "ijson-jcs-fuzz" +version = "0.0.0" +dependencies = [ + "ijson-jcs", + "libfuzzer-sys", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom", + "libc", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libfuzzer-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2" +dependencies = [ + "arbitrary", + "cc", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "ryu-js" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f232fd0249f55adbe7f15bee58bbbd3d40708000b84e6482066d2ba599e08a9" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..0eecf40 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: MPL-2.0 +[package] +name = "ijson-jcs-fuzz" +version = "0.0.0" +publish = false +edition = "2024" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.ijson-jcs] +path = ".." + +[workspace] + +[[bin]] +name = "parse_jcs" +path = "fuzz_targets/parse_jcs.rs" +test = false +doc = false +bench = false + +[[bin]] +name = "canon_roundtrip" +path = "fuzz_targets/canon_roundtrip.rs" +test = false +doc = false +bench = false + +[[bin]] +name = "cli_input" +path = "fuzz_targets/cli_input.rs" +test = false +doc = false +bench = false diff --git a/fuzz/README.adoc b/fuzz/README.adoc new file mode 100644 index 0000000..1a0f381 --- /dev/null +++ b/fuzz/README.adoc @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MPL-2.0 += Fuzz targets + +Requires nightly Rust and `cargo install cargo-fuzz --locked --version 0.13.2`. +The repository toolchain pin (stable) is unaffected: run `cargo +nightly fuzz ...`. + +[cols="1,3",options="header"] +|=== +| Target | Property +| `parse_jcs` | never panics; anything accepted is renderable by `to_jcs` +| `canon_roundtrip` | `parse_jcs(canon(x))` succeeds and `canon` is idempotent +| `cli_input` | the byte path behind `canon`/`check`/`fix`/`jsonld`/JSON Lines never panics; estate form == library bytes + one LF; strict idempotence +|=== + +Seed corpora (`fuzz/corpus/*`): RFC 8785 section 3.2.3 and 3.2.4 examples, +all Appendix B number literals (silence fixtures), plus refusals: duplicate +key, lone surrogate, truncated input, overflow (firing fixtures for the refusal +paths). Run against a copy, because libFuzzer writes new inputs into the +corpus directory it is given: + + cp -r fuzz/corpus/parse_jcs /tmp/c && cargo +nightly fuzz run parse_jcs /tmp/c -- -max_total_time=60 + +`cli_input` does not reach the binary's size-bounded stdin reader (`read_bounded` +is private to `src/bin`); that limit is covered by `tests/cli.rs`. Fuzzing is +evidence, not proof; no sustained campaign has been run (smoke only). +Verified once locally that the harness fires: with the idempotence assertion +inverted, `canon_roundtrip` fails within seconds. diff --git a/fuzz/corpus/canon_roundtrip/neg-duplicate-key b/fuzz/corpus/canon_roundtrip/neg-duplicate-key new file mode 100644 index 0000000..0c4547d --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/neg-duplicate-key @@ -0,0 +1 @@ +{"a":1,"a":2} \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/neg-lone-surrogate b/fuzz/corpus/canon_roundtrip/neg-lone-surrogate new file mode 100644 index 0000000..4a1cb1e --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/neg-lone-surrogate @@ -0,0 +1 @@ +"\ud800" \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/neg-overflow b/fuzz/corpus/canon_roundtrip/neg-overflow new file mode 100644 index 0000000..df8a56e --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/neg-overflow @@ -0,0 +1 @@ +1e999 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/neg-truncated b/fuzz/corpus/canon_roundtrip/neg-truncated new file mode 100644 index 0000000..3ef538a --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/neg-truncated @@ -0,0 +1 @@ +{"a": \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/neg-truncated-array b/fuzz/corpus/canon_roundtrip/neg-truncated-array new file mode 100644 index 0000000..f1c3a0a --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/neg-truncated-array @@ -0,0 +1 @@ +[1,2 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-3.2.3-key-order b/fuzz/corpus/canon_roundtrip/rfc8785-3.2.3-key-order new file mode 100644 index 0000000..ca2915a --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-3.2.3-key-order @@ -0,0 +1 @@ +{"€":"Euro Sign","\r":"Carriage Return","דּ":"Hebrew Letter Dalet With Dagesh","1":"One","😀":"Emoji: Grinning Face","\u0080":"Control","ö":"Latin Small Letter O With Diaeresis"} \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-3.2.4-example b/fuzz/corpus/canon_roundtrip/rfc8785-3.2.4-example new file mode 100644 index 0000000..8766d6a --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-3.2.4-example @@ -0,0 +1 @@ +{"numbers":[333333333.33333329,1E30,4.50,2e-3,0.000000000000000000000000001],"string":"€$\u000F\u000aA'B"\\\\"\/","literals":[null,true,false]} \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-01 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-01 new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-01 @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-02 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-02 new file mode 100644 index 0000000..16593f0 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-02 @@ -0,0 +1 @@ +-0 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-03 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-03 new file mode 100644 index 0000000..f366002 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-03 @@ -0,0 +1 @@ +5e-324 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-04 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-04 new file mode 100644 index 0000000..cf33a89 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-04 @@ -0,0 +1 @@ +-5e-324 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-05 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-05 new file mode 100644 index 0000000..c65d7fb --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-05 @@ -0,0 +1 @@ +1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-06 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-06 new file mode 100644 index 0000000..428f19f --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-06 @@ -0,0 +1 @@ +-1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-07 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-07 new file mode 100644 index 0000000..9f0aa82 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-07 @@ -0,0 +1 @@ +9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-08 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-08 new file mode 100644 index 0000000..1c92a70 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-08 @@ -0,0 +1 @@ +-9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-09 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-09 new file mode 100644 index 0000000..f0b46b9 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-09 @@ -0,0 +1 @@ +295147905179352830000 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-10 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-10 new file mode 100644 index 0000000..a439590 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-10 @@ -0,0 +1 @@ +9.999999999999997e+22 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-11 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-11 new file mode 100644 index 0000000..b8ccc51 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-11 @@ -0,0 +1 @@ +1e+23 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-12 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-12 new file mode 100644 index 0000000..b62df4a --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-12 @@ -0,0 +1 @@ +1.0000000000000001e+23 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-13 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-13 new file mode 100644 index 0000000..c793ac7 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-13 @@ -0,0 +1 @@ +999999999999999700000 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-14 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-14 new file mode 100644 index 0000000..57c3dff --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-14 @@ -0,0 +1 @@ +999999999999999900000 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-15 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-15 new file mode 100644 index 0000000..af98fb7 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-15 @@ -0,0 +1 @@ +1e+21 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-16 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-16 new file mode 100644 index 0000000..adbcedf --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-16 @@ -0,0 +1 @@ +9.999999999999997e-7 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-17 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-17 new file mode 100644 index 0000000..59a3aa2 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-17 @@ -0,0 +1 @@ +0.000001 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-18 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-18 new file mode 100644 index 0000000..8db0239 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-18 @@ -0,0 +1 @@ +333333333.3333332 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-19 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-19 new file mode 100644 index 0000000..aaff006 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-19 @@ -0,0 +1 @@ +333333333.33333325 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-20 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-20 new file mode 100644 index 0000000..db7b315 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-20 @@ -0,0 +1 @@ +333333333.3333333 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-21 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-21 new file mode 100644 index 0000000..8c95ae7 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-21 @@ -0,0 +1 @@ +333333333.3333334 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-22 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-22 new file mode 100644 index 0000000..3d0a24b --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-22 @@ -0,0 +1 @@ +333333333.33333343 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-23 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-23 new file mode 100644 index 0000000..4e9fc01 --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-23 @@ -0,0 +1 @@ +-0.0000033333333333333333 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-24 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-24 new file mode 100644 index 0000000..1cb539e --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-24 @@ -0,0 +1 @@ +1424953923781206.2 \ No newline at end of file diff --git a/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-25 b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-25 new file mode 100644 index 0000000..a6e7c1e --- /dev/null +++ b/fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-25 @@ -0,0 +1 @@ +1424953923781206.25 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/jsonld-good b/fuzz/corpus/cli_input/jsonld-good new file mode 100644 index 0000000..3801610 --- /dev/null +++ b/fuzz/corpus/cli_input/jsonld-good @@ -0,0 +1 @@ +{"@context":{"name":"https://schema.org/name"},"@id":"https://example.invalid/alice","name":"Alice"} diff --git a/fuzz/corpus/cli_input/neg-duplicate-key b/fuzz/corpus/cli_input/neg-duplicate-key new file mode 100644 index 0000000..0c4547d --- /dev/null +++ b/fuzz/corpus/cli_input/neg-duplicate-key @@ -0,0 +1 @@ +{"a":1,"a":2} \ No newline at end of file diff --git a/fuzz/corpus/cli_input/neg-lone-surrogate b/fuzz/corpus/cli_input/neg-lone-surrogate new file mode 100644 index 0000000..4a1cb1e --- /dev/null +++ b/fuzz/corpus/cli_input/neg-lone-surrogate @@ -0,0 +1 @@ +"\ud800" \ No newline at end of file diff --git a/fuzz/corpus/cli_input/neg-overflow b/fuzz/corpus/cli_input/neg-overflow new file mode 100644 index 0000000..df8a56e --- /dev/null +++ b/fuzz/corpus/cli_input/neg-overflow @@ -0,0 +1 @@ +1e999 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/neg-truncated b/fuzz/corpus/cli_input/neg-truncated new file mode 100644 index 0000000..3ef538a --- /dev/null +++ b/fuzz/corpus/cli_input/neg-truncated @@ -0,0 +1 @@ +{"a": \ No newline at end of file diff --git a/fuzz/corpus/cli_input/neg-truncated-array b/fuzz/corpus/cli_input/neg-truncated-array new file mode 100644 index 0000000..f1c3a0a --- /dev/null +++ b/fuzz/corpus/cli_input/neg-truncated-array @@ -0,0 +1 @@ +[1,2 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/records-good.jsonl b/fuzz/corpus/cli_input/records-good.jsonl new file mode 100644 index 0000000..cb18f27 --- /dev/null +++ b/fuzz/corpus/cli_input/records-good.jsonl @@ -0,0 +1,2 @@ +{"a":1} +{"b":[1,2]} diff --git a/fuzz/corpus/cli_input/rfc8785-3.2.3-key-order b/fuzz/corpus/cli_input/rfc8785-3.2.3-key-order new file mode 100644 index 0000000..ca2915a --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-3.2.3-key-order @@ -0,0 +1 @@ +{"€":"Euro Sign","\r":"Carriage Return","דּ":"Hebrew Letter Dalet With Dagesh","1":"One","😀":"Emoji: Grinning Face","\u0080":"Control","ö":"Latin Small Letter O With Diaeresis"} \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-3.2.4-example b/fuzz/corpus/cli_input/rfc8785-3.2.4-example new file mode 100644 index 0000000..8766d6a --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-3.2.4-example @@ -0,0 +1 @@ +{"numbers":[333333333.33333329,1E30,4.50,2e-3,0.000000000000000000000000001],"string":"€$\u000F\u000aA'B"\\\\"\/","literals":[null,true,false]} \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-01 b/fuzz/corpus/cli_input/rfc8785-appendix-b-01 new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-01 @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-02 b/fuzz/corpus/cli_input/rfc8785-appendix-b-02 new file mode 100644 index 0000000..16593f0 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-02 @@ -0,0 +1 @@ +-0 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-03 b/fuzz/corpus/cli_input/rfc8785-appendix-b-03 new file mode 100644 index 0000000..f366002 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-03 @@ -0,0 +1 @@ +5e-324 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-04 b/fuzz/corpus/cli_input/rfc8785-appendix-b-04 new file mode 100644 index 0000000..cf33a89 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-04 @@ -0,0 +1 @@ +-5e-324 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-05 b/fuzz/corpus/cli_input/rfc8785-appendix-b-05 new file mode 100644 index 0000000..c65d7fb --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-05 @@ -0,0 +1 @@ +1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-06 b/fuzz/corpus/cli_input/rfc8785-appendix-b-06 new file mode 100644 index 0000000..428f19f --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-06 @@ -0,0 +1 @@ +-1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-07 b/fuzz/corpus/cli_input/rfc8785-appendix-b-07 new file mode 100644 index 0000000..9f0aa82 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-07 @@ -0,0 +1 @@ +9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-08 b/fuzz/corpus/cli_input/rfc8785-appendix-b-08 new file mode 100644 index 0000000..1c92a70 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-08 @@ -0,0 +1 @@ +-9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-09 b/fuzz/corpus/cli_input/rfc8785-appendix-b-09 new file mode 100644 index 0000000..f0b46b9 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-09 @@ -0,0 +1 @@ +295147905179352830000 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-10 b/fuzz/corpus/cli_input/rfc8785-appendix-b-10 new file mode 100644 index 0000000..a439590 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-10 @@ -0,0 +1 @@ +9.999999999999997e+22 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-11 b/fuzz/corpus/cli_input/rfc8785-appendix-b-11 new file mode 100644 index 0000000..b8ccc51 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-11 @@ -0,0 +1 @@ +1e+23 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-12 b/fuzz/corpus/cli_input/rfc8785-appendix-b-12 new file mode 100644 index 0000000..b62df4a --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-12 @@ -0,0 +1 @@ +1.0000000000000001e+23 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-13 b/fuzz/corpus/cli_input/rfc8785-appendix-b-13 new file mode 100644 index 0000000..c793ac7 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-13 @@ -0,0 +1 @@ +999999999999999700000 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-14 b/fuzz/corpus/cli_input/rfc8785-appendix-b-14 new file mode 100644 index 0000000..57c3dff --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-14 @@ -0,0 +1 @@ +999999999999999900000 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-15 b/fuzz/corpus/cli_input/rfc8785-appendix-b-15 new file mode 100644 index 0000000..af98fb7 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-15 @@ -0,0 +1 @@ +1e+21 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-16 b/fuzz/corpus/cli_input/rfc8785-appendix-b-16 new file mode 100644 index 0000000..adbcedf --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-16 @@ -0,0 +1 @@ +9.999999999999997e-7 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-17 b/fuzz/corpus/cli_input/rfc8785-appendix-b-17 new file mode 100644 index 0000000..59a3aa2 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-17 @@ -0,0 +1 @@ +0.000001 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-18 b/fuzz/corpus/cli_input/rfc8785-appendix-b-18 new file mode 100644 index 0000000..8db0239 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-18 @@ -0,0 +1 @@ +333333333.3333332 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-19 b/fuzz/corpus/cli_input/rfc8785-appendix-b-19 new file mode 100644 index 0000000..aaff006 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-19 @@ -0,0 +1 @@ +333333333.33333325 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-20 b/fuzz/corpus/cli_input/rfc8785-appendix-b-20 new file mode 100644 index 0000000..db7b315 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-20 @@ -0,0 +1 @@ +333333333.3333333 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-21 b/fuzz/corpus/cli_input/rfc8785-appendix-b-21 new file mode 100644 index 0000000..8c95ae7 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-21 @@ -0,0 +1 @@ +333333333.3333334 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-22 b/fuzz/corpus/cli_input/rfc8785-appendix-b-22 new file mode 100644 index 0000000..3d0a24b --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-22 @@ -0,0 +1 @@ +333333333.33333343 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-23 b/fuzz/corpus/cli_input/rfc8785-appendix-b-23 new file mode 100644 index 0000000..4e9fc01 --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-23 @@ -0,0 +1 @@ +-0.0000033333333333333333 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-24 b/fuzz/corpus/cli_input/rfc8785-appendix-b-24 new file mode 100644 index 0000000..1cb539e --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-24 @@ -0,0 +1 @@ +1424953923781206.2 \ No newline at end of file diff --git a/fuzz/corpus/cli_input/rfc8785-appendix-b-25 b/fuzz/corpus/cli_input/rfc8785-appendix-b-25 new file mode 100644 index 0000000..a6e7c1e --- /dev/null +++ b/fuzz/corpus/cli_input/rfc8785-appendix-b-25 @@ -0,0 +1 @@ +1424953923781206.25 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/neg-duplicate-key b/fuzz/corpus/parse_jcs/neg-duplicate-key new file mode 100644 index 0000000..0c4547d --- /dev/null +++ b/fuzz/corpus/parse_jcs/neg-duplicate-key @@ -0,0 +1 @@ +{"a":1,"a":2} \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/neg-lone-surrogate b/fuzz/corpus/parse_jcs/neg-lone-surrogate new file mode 100644 index 0000000..4a1cb1e --- /dev/null +++ b/fuzz/corpus/parse_jcs/neg-lone-surrogate @@ -0,0 +1 @@ +"\ud800" \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/neg-overflow b/fuzz/corpus/parse_jcs/neg-overflow new file mode 100644 index 0000000..df8a56e --- /dev/null +++ b/fuzz/corpus/parse_jcs/neg-overflow @@ -0,0 +1 @@ +1e999 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/neg-truncated b/fuzz/corpus/parse_jcs/neg-truncated new file mode 100644 index 0000000..3ef538a --- /dev/null +++ b/fuzz/corpus/parse_jcs/neg-truncated @@ -0,0 +1 @@ +{"a": \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/neg-truncated-array b/fuzz/corpus/parse_jcs/neg-truncated-array new file mode 100644 index 0000000..f1c3a0a --- /dev/null +++ b/fuzz/corpus/parse_jcs/neg-truncated-array @@ -0,0 +1 @@ +[1,2 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-3.2.3-key-order b/fuzz/corpus/parse_jcs/rfc8785-3.2.3-key-order new file mode 100644 index 0000000..ca2915a --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-3.2.3-key-order @@ -0,0 +1 @@ +{"€":"Euro Sign","\r":"Carriage Return","דּ":"Hebrew Letter Dalet With Dagesh","1":"One","😀":"Emoji: Grinning Face","\u0080":"Control","ö":"Latin Small Letter O With Diaeresis"} \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-3.2.4-example b/fuzz/corpus/parse_jcs/rfc8785-3.2.4-example new file mode 100644 index 0000000..8766d6a --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-3.2.4-example @@ -0,0 +1 @@ +{"numbers":[333333333.33333329,1E30,4.50,2e-3,0.000000000000000000000000001],"string":"€$\u000F\u000aA'B"\\\\"\/","literals":[null,true,false]} \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-01 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-01 new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-01 @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-02 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-02 new file mode 100644 index 0000000..16593f0 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-02 @@ -0,0 +1 @@ +-0 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-03 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-03 new file mode 100644 index 0000000..f366002 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-03 @@ -0,0 +1 @@ +5e-324 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-04 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-04 new file mode 100644 index 0000000..cf33a89 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-04 @@ -0,0 +1 @@ +-5e-324 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-05 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-05 new file mode 100644 index 0000000..c65d7fb --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-05 @@ -0,0 +1 @@ +1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-06 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-06 new file mode 100644 index 0000000..428f19f --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-06 @@ -0,0 +1 @@ +-1.7976931348623157e+308 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-07 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-07 new file mode 100644 index 0000000..9f0aa82 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-07 @@ -0,0 +1 @@ +9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-08 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-08 new file mode 100644 index 0000000..1c92a70 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-08 @@ -0,0 +1 @@ +-9007199254740992 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-09 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-09 new file mode 100644 index 0000000..f0b46b9 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-09 @@ -0,0 +1 @@ +295147905179352830000 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-10 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-10 new file mode 100644 index 0000000..a439590 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-10 @@ -0,0 +1 @@ +9.999999999999997e+22 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-11 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-11 new file mode 100644 index 0000000..b8ccc51 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-11 @@ -0,0 +1 @@ +1e+23 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-12 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-12 new file mode 100644 index 0000000..b62df4a --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-12 @@ -0,0 +1 @@ +1.0000000000000001e+23 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-13 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-13 new file mode 100644 index 0000000..c793ac7 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-13 @@ -0,0 +1 @@ +999999999999999700000 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-14 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-14 new file mode 100644 index 0000000..57c3dff --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-14 @@ -0,0 +1 @@ +999999999999999900000 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-15 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-15 new file mode 100644 index 0000000..af98fb7 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-15 @@ -0,0 +1 @@ +1e+21 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-16 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-16 new file mode 100644 index 0000000..adbcedf --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-16 @@ -0,0 +1 @@ +9.999999999999997e-7 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-17 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-17 new file mode 100644 index 0000000..59a3aa2 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-17 @@ -0,0 +1 @@ +0.000001 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-18 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-18 new file mode 100644 index 0000000..8db0239 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-18 @@ -0,0 +1 @@ +333333333.3333332 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-19 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-19 new file mode 100644 index 0000000..aaff006 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-19 @@ -0,0 +1 @@ +333333333.33333325 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-20 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-20 new file mode 100644 index 0000000..db7b315 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-20 @@ -0,0 +1 @@ +333333333.3333333 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-21 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-21 new file mode 100644 index 0000000..8c95ae7 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-21 @@ -0,0 +1 @@ +333333333.3333334 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-22 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-22 new file mode 100644 index 0000000..3d0a24b --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-22 @@ -0,0 +1 @@ +333333333.33333343 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-23 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-23 new file mode 100644 index 0000000..4e9fc01 --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-23 @@ -0,0 +1 @@ +-0.0000033333333333333333 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-24 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-24 new file mode 100644 index 0000000..1cb539e --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-24 @@ -0,0 +1 @@ +1424953923781206.2 \ No newline at end of file diff --git a/fuzz/corpus/parse_jcs/rfc8785-appendix-b-25 b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-25 new file mode 100644 index 0000000..a6e7c1e --- /dev/null +++ b/fuzz/corpus/parse_jcs/rfc8785-appendix-b-25 @@ -0,0 +1 @@ +1424953923781206.25 \ No newline at end of file diff --git a/fuzz/fuzz_targets/canon_roundtrip.rs b/fuzz/fuzz_targets/canon_roundtrip.rs new file mode 100644 index 0000000..2345110 --- /dev/null +++ b/fuzz/fuzz_targets/canon_roundtrip.rs @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MPL-2.0 +//! Canonicalisation round trip on the RFC 8785 binary64 model: +//! `parse(canon(x))` succeeds and `canon(parse(canon(x))) == canon(x)`. +#![no_main] + +use ijson_jcs::{parse_jcs, to_jcs}; +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + let Ok(text) = std::str::from_utf8(data) else { + return; + }; + let Ok(value) = parse_jcs(text) else { + return; + }; + let once = to_jcs(&value).expect("accepted value must canonicalise"); + let once_text = std::str::from_utf8(&once).expect("JCS output is UTF-8"); + let reparsed = parse_jcs(once_text).expect("parse(canon(x)) must succeed"); + let twice = to_jcs(&reparsed).expect("reparsed value must canonicalise"); + assert_eq!(once, twice, "canon is not idempotent"); +}); diff --git a/fuzz/fuzz_targets/cli_input.rs b/fuzz/fuzz_targets/cli_input.rs new file mode 100644 index 0000000..01346ce --- /dev/null +++ b/fuzz/fuzz_targets/cli_input.rs @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MPL-2.0 +//! The byte-level path behind `ijson-jcs canon|check|fix|jsonld` and the +//! JSON Lines mode. The CLI's size-bounded reader lives in the binary and is +//! not reachable from here; its limit is covered by tests/cli.rs. What is +//! fuzzed is everything the CLI does with the bytes once read. +#![no_main] + +use ijson_jcs::{ + CanonicalProfile, IJsonError, canonicalize_bytes, canonicalize_jsonld_document, + canonicalize_records, classify, classify_records, estate_file_from_bytes, +}; +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + // jsonld and records must refuse or succeed, never panic. + let _ = canonicalize_jsonld_document(data); + let _ = canonicalize_records(data); + let _ = classify_records(data); + + for profile in [ + CanonicalProfile::LibraryBytes, + CanonicalProfile::EstateFile, + CanonicalProfile::Tolerant, + ] { + let _ = classify(data, profile); + } + + if let Ok(canon) = canonicalize_bytes(data) { + // The estate form is exactly the library bytes plus one line feed. + let file = estate_file_from_bytes(data).expect("estate form of accepted input"); + assert_eq!(file.len(), canon.len() + 1); + assert_eq!(&file[..canon.len()], &canon[..]); + assert_eq!(file.last(), Some(&b'\n')); + // Idempotence on the strict domain. The one documented exception is + // output whose integral doubles exceed 2^53-1, which the strict + // integer-token profile refuses (see CLI usage text). + match canonicalize_bytes(&canon) { + Ok(again) => assert_eq!(again, canon, "canon not idempotent"), + Err(IJsonError::ValidationError(ijson_jcs::ValidationError::UnsafeInteger { .. })) => {} + Err(other) => panic!("canonical output refused: {other}"), + } + } +}); diff --git a/fuzz/fuzz_targets/parse_jcs.rs b/fuzz/fuzz_targets/parse_jcs.rs new file mode 100644 index 0000000..6fbf9ac --- /dev/null +++ b/fuzz/fuzz_targets/parse_jcs.rs @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: MPL-2.0 +//! `parse_jcs` must never panic, and anything it accepts must be renderable. +#![no_main] + +use ijson_jcs::{parse_jcs, to_jcs}; +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + let Ok(text) = std::str::from_utf8(data) else { + return; + }; + if let Ok(value) = parse_jcs(text) { + // parse_jcs validates canonicalisability, so rendering must succeed. + to_jcs(&value).expect("parse_jcs accepted a value that to_jcs refuses"); + } +});