Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -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",
},
},
],
},
},
}
2 changes: 2 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
artifacts
221 changes: 221 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions fuzz/README.adoc
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/neg-duplicate-key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":1,"a":2}
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/neg-lone-surrogate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"\ud800"
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/neg-overflow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1e999
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/neg-truncated
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/neg-truncated-array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1,2
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-3.2.3-key-order
Original file line number Diff line number Diff line change
@@ -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"}
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-3.2.4-example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"numbers":[333333333.33333329,1E30,4.50,2e-3,0.000000000000000000000000001],"string":"€$\u000F\u000aA'B"\\\\"\/","literals":[null,true,false]}
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-02
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-0
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-03
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5e-324
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-04
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-5e-324
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-05
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.7976931348623157e+308
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-06
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-1.7976931348623157e+308
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-07
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9007199254740992
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-08
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-9007199254740992
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-09
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
295147905179352830000
1 change: 1 addition & 0 deletions fuzz/corpus/canon_roundtrip/rfc8785-appendix-b-10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.999999999999997e+22
Loading
Loading