From d690d2af8175e1a5015d3b226695f15284dc0307 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 09:01:23 +0200 Subject: [PATCH 01/21] initial fuzz target --- fuzz/.gitignore | 4 ++++ fuzz/Cargo.toml | 21 +++++++++++++++++++++ fuzz/fuzz_targets/fuzz_tests.rs | 7 +++++++ 3 files changed, 32 insertions(+) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzz_targets/fuzz_tests.rs diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..1a45eee --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ +target +corpus +artifacts +coverage diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..0b07b2e --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "ijson-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.ijson] +path = ".." + +[[bin]] +name = "fuzz_tests" +path = "fuzz_targets/fuzz_tests.rs" +test = false +doc = false +bench = false diff --git a/fuzz/fuzz_targets/fuzz_tests.rs b/fuzz/fuzz_targets/fuzz_tests.rs new file mode 100644 index 0000000..43a88c1 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_tests.rs @@ -0,0 +1,7 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + // fuzzed code goes here +}); From 2ae12e3bb69a786db82bb3a2243641195e5cf3d8 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 14:27:01 +0200 Subject: [PATCH 02/21] simple test + ci files --- .github/workflows/build_and_test.yml | 28 ++++++++++++++++++++++++ .github/workflows/fuzz_tests.yml | 32 ++++++++++++++++++++++++++++ Cargo.toml | 14 ++++++++++-- fuzz/Cargo.toml | 7 ++++-- fuzz/fuzz_targets/fuzz_string.rs | 13 +++++++++++ fuzz/fuzz_targets/fuzz_tests.rs | 7 ------ fuzz/rust-toolchain.toml | 2 ++ 7 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build_and_test.yml create mode 100644 .github/workflows/fuzz_tests.yml create mode 100644 fuzz/fuzz_targets/fuzz_string.rs delete mode 100644 fuzz/fuzz_targets/fuzz_tests.rs create mode 100644 fuzz/rust-toolchain.toml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 0000000..ae9dd26 --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,28 @@ +name: Event CI + +permissions: + contents: read + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_and_test: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust nightly + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + + - name: Build + run: cargo build + + - name: Test + run: cargo test -- --test-threads=1 + diff --git a/.github/workflows/fuzz_tests.yml b/.github/workflows/fuzz_tests.yml new file mode 100644 index 0000000..5dced32 --- /dev/null +++ b/.github/workflows/fuzz_tests.yml @@ -0,0 +1,32 @@ +name: Smoke-Test Fuzz Targets + +on: + pull_request: + +jobs: + fuzz: + runs-on: ubuntu-latest + + env: + CARGO_FUZZ_VERSION: 0.13.0 + FUZZ_TIME: 180 + + strategy: + matrix: + include: + - fuzz_target: fuzz_string + + steps: + - uses: actions/checkout@v4 + + - run: rustup toolchain install nightly + - run: rustup default nightly + - uses: actions/cache@v4 + with: + path: ${{ runner.tool_cache }}/cargo-fuzz + key: cargo-fuzz-bin-${{ env.CARGO_FUZZ_VERSION }} + - run: echo "${{ runner.tool_cache }}/cargo-fuzz/bin" >> $GITHUB_PATH + - run: cargo install --root "${{ runner.tool_cache }}/cargo-fuzz" --version ${{ env.CARGO_FUZZ_VERSION }} cargo-fuzz --locked + + - run: cd fuzz + - run: cargo fuzz run ${{ matrix.fuzz_target }} -- -max_total_time=${{ env.FUZZ_TIME }} --release diff --git a/Cargo.toml b/Cargo.toml index 4c93328..06ef9f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[workspace] +members = ["fuzz"] + [package] name = "ijson" version = "0.1.3" @@ -14,12 +17,17 @@ default = [] tracing = ["mockalloc/tracing"] thread_safe = [] +[workspace.dependencies] +serde = "1.0.117" +serde_json = "1.0.59" + + [dependencies] hashbrown = "0.13.2" dashmap = { version = "5.4", features = ["raw-api"] } lazy_static = "1.4.0" -serde = "1.0.117" -serde_json = "1.0.59" +serde = { workspace = true } +serde_json = { workspace = true } ctor = { version = "0.1.16", optional = true } paste = "1.0.15" half = "2.0.0" @@ -28,4 +36,6 @@ half = "2.0.0" mockalloc = "0.1.2" ctor = "0.1.16" rand = "0.8.4" +cargo-fuzz = "0.13.0" +ijson-fuzz = { path = "fuzz" } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 0b07b2e..7fa911e 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -9,13 +9,16 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" +arbitrary = { version = "1.3", features = ["derive"] } +serde = { workspace = true } +serde_json = { workspace = true } [dependencies.ijson] path = ".." [[bin]] -name = "fuzz_tests" -path = "fuzz_targets/fuzz_tests.rs" +name = "fuzz_string" +path = "fuzz_targets/fuzz_string.rs" test = false doc = false bench = false diff --git a/fuzz/fuzz_targets/fuzz_string.rs b/fuzz/fuzz_targets/fuzz_string.rs new file mode 100644 index 0000000..32d0254 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_string.rs @@ -0,0 +1,13 @@ +#![no_main] + +use ijson::IValue; +use libfuzzer_sys::fuzz_target; +use serde::Deserialize; + +fuzz_target!(|data: &str| { + if data.is_empty() { + return; + } + let mut deserializer = serde_json::Deserializer::from_str(data); + let _ = IValue::deserialize(&mut deserializer); +}); diff --git a/fuzz/fuzz_targets/fuzz_tests.rs b/fuzz/fuzz_targets/fuzz_tests.rs deleted file mode 100644 index 43a88c1..0000000 --- a/fuzz/fuzz_targets/fuzz_tests.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![no_main] - -use libfuzzer_sys::fuzz_target; - -fuzz_target!(|data: &[u8]| { - // fuzzed code goes here -}); diff --git a/fuzz/rust-toolchain.toml b/fuzz/rust-toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/fuzz/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" From ab64488181c6ab99888a52226dbbc1c6709329fa Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 14:35:43 +0200 Subject: [PATCH 03/21] test --- .github/workflows/build_and_test.yml | 29 +++-- .github/workflows/fuzz_tests.yml | 3 +- .github/workflows/toolchain.yml | 175 --------------------------- 3 files changed, 21 insertions(+), 186 deletions(-) delete mode 100644 .github/workflows/toolchain.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ae9dd26..1a3294b 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,10 +1,6 @@ name: Event CI -permissions: - contents: read - -on: - pull_request: +on: [push, pull_request] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -17,12 +13,27 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install Rust nightly - run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + - name: Rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features -- -D warnings - name: Build - run: cargo build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --all-features - name: Test - run: cargo test -- --test-threads=1 + uses: actions-rs/cargo@v1 + with: + command: test + args: -- --test-threads=1 diff --git a/.github/workflows/fuzz_tests.yml b/.github/workflows/fuzz_tests.yml index 5dced32..82c6149 100644 --- a/.github/workflows/fuzz_tests.yml +++ b/.github/workflows/fuzz_tests.yml @@ -1,7 +1,6 @@ name: Smoke-Test Fuzz Targets -on: - pull_request: +on: [push, pull_request] jobs: fuzz: diff --git a/.github/workflows/toolchain.yml b/.github/workflows/toolchain.yml deleted file mode 100644 index 43690e9..0000000 --- a/.github/workflows/toolchain.yml +++ /dev/null @@ -1,175 +0,0 @@ -on: [push, pull_request] - -name: CI - -jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - args: --all-features - - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - clippy: - name: Clippy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-features -- -D warnings - - test: - name: Test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: test - args: -- --test-threads=1 - - test_thread_unsafe: - name: Test unsafe thread - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: test - args: --no-default-features -- --test-threads=1 - - test_miri: - name: Test (Miri) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: miri - - uses: actions-rs/cargo@v1 - with: - command: miri - args: test - env: - MIRIFLAGS: "-Zmiri-disable-isolation" - - test_miri_32bit_linux: - name: Test (Miri i686-unknown-linux-gnu) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: miri - target: i686-unknown-linux-gnu - - uses: actions-rs/cargo@v1 - with: - command: miri - args: test --target i686-unknown-linux-gnu - env: - MIRIFLAGS: "-Zmiri-disable-isolation" - - test_miri_32bit_windows: - name: Test (Miri i686-pc-windows-msvc) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: miri - target: i686-pc-windows-msvc - - uses: actions-rs/cargo@v1 - with: - command: miri - args: test --target i686-pc-windows-msvc - env: - MIRIFLAGS: "-Zmiri-disable-isolation" - - test_nightly: - name: Test (Nightly) - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: llvm-tools-preview - - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-binutils rustfilt - - name: Build tests - run: | - cargo rustc --message-format=json --tests -- -Zinstrument-coverage | jq -r '.executable | strings' > executables.txt - - name: Run tests - run: | - while read p; do - exec "$p" --test-threads=1 - done lcov.info - - name: Upload coverage report - uses: codecov/codecov-action@v1 - with: - fail_ci_if_error: true - - uses: actions/upload-artifact@v2 - with: - name: Upload coverage artifact - path: lcov.info From dbbcc295ff17aa7b2acffc2e5f8c0c208f4cd3ae Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 14:51:43 +0200 Subject: [PATCH 04/21] test --- .github/workflows/build_and_test.yml | 12 +++++++-- .github/workflows/fuzz_tests.yml | 37 +++++++++++++++------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1a3294b..7e912d6 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,6 +1,6 @@ name: Event CI -on: [push, pull_request] +on: [pull_request] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -12,8 +12,16 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + + - name: Install Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt, clippy - - name: Rustfmt + - name: Cargo Format uses: actions-rs/cargo@v1 with: command: fmt diff --git a/.github/workflows/fuzz_tests.yml b/.github/workflows/fuzz_tests.yml index 82c6149..42aa5a0 100644 --- a/.github/workflows/fuzz_tests.yml +++ b/.github/workflows/fuzz_tests.yml @@ -1,11 +1,9 @@ name: Smoke-Test Fuzz Targets -on: [push, pull_request] +on: [pull_request] jobs: fuzz: - runs-on: ubuntu-latest - env: CARGO_FUZZ_VERSION: 0.13.0 FUZZ_TIME: 180 @@ -14,18 +12,23 @@ jobs: matrix: include: - fuzz_target: fuzz_string - + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - run: rustup toolchain install nightly - - run: rustup default nightly - - uses: actions/cache@v4 - with: - path: ${{ runner.tool_cache }}/cargo-fuzz - key: cargo-fuzz-bin-${{ env.CARGO_FUZZ_VERSION }} - - run: echo "${{ runner.tool_cache }}/cargo-fuzz/bin" >> $GITHUB_PATH - - run: cargo install --root "${{ runner.tool_cache }}/cargo-fuzz" --version ${{ env.CARGO_FUZZ_VERSION }} cargo-fuzz --locked - - - run: cd fuzz - - run: cargo fuzz run ${{ matrix.fuzz_target }} -- -max_total_time=${{ env.FUZZ_TIME }} --release + - name: Setup + uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: cargo-fuzz + + - uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-fuzz --version ${{ env.CARGO_FUZZ_VERSION }} + + - name: Fuzz + working-directory: fuzz + run: cargo fuzz run ${{ matrix.fuzz_target }} --release -- -max_total_time=${{ env.FUZZ_TIME }} From a65efd67d42a978472437f84f9033ab33d434ead Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:06:50 +0200 Subject: [PATCH 05/21] project structure --- .../build_and_test}/build_and_test.yml | 9 +++------ .../fuzz_tests}/fuzz_tests.yml | 3 ++- .github/workflows/ci.yml | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) rename .github/{workflows => actions/build_and_test}/build_and_test.yml (87%) rename .github/{workflows => actions/fuzz_tests}/fuzz_tests.yml (97%) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build_and_test.yml b/.github/actions/build_and_test/build_and_test.yml similarity index 87% rename from .github/workflows/build_and_test.yml rename to .github/actions/build_and_test/build_and_test.yml index 7e912d6..4dd11e9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/actions/build_and_test/build_and_test.yml @@ -1,10 +1,7 @@ -name: Event CI +name: Build and Test -on: [pull_request] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true +on: + workflow_call: jobs: build_and_test: diff --git a/.github/workflows/fuzz_tests.yml b/.github/actions/fuzz_tests/fuzz_tests.yml similarity index 97% rename from .github/workflows/fuzz_tests.yml rename to .github/actions/fuzz_tests/fuzz_tests.yml index 42aa5a0..11af723 100644 --- a/.github/workflows/fuzz_tests.yml +++ b/.github/actions/fuzz_tests/fuzz_tests.yml @@ -1,6 +1,7 @@ name: Smoke-Test Fuzz Targets -on: [pull_request] +on: + workflow_call: jobs: fuzz: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7665815 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: CI + +on: [pull_request] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_and_test: + name: Build and Test + uses: ./.github/actions/build_and_test/build_and_test.yml + + fuzz_tests: + name: Fuzz Tests + uses: ./.github/actions/fuzz_tests/fuzz_tests.yml + From a91e2219d4952bbf8b61d4ae24433c9e53ac80ac Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:08:44 +0200 Subject: [PATCH 06/21] project structure --- .github/actions/build_and_test/build_and_test.yml | 2 -- .github/actions/fuzz_tests/fuzz_tests.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/actions/build_and_test/build_and_test.yml b/.github/actions/build_and_test/build_and_test.yml index 4dd11e9..8bd6519 100644 --- a/.github/actions/build_and_test/build_and_test.yml +++ b/.github/actions/build_and_test/build_and_test.yml @@ -1,7 +1,5 @@ name: Build and Test -on: - workflow_call: jobs: build_and_test: diff --git a/.github/actions/fuzz_tests/fuzz_tests.yml b/.github/actions/fuzz_tests/fuzz_tests.yml index 11af723..e856196 100644 --- a/.github/actions/fuzz_tests/fuzz_tests.yml +++ b/.github/actions/fuzz_tests/fuzz_tests.yml @@ -1,7 +1,5 @@ name: Smoke-Test Fuzz Targets -on: - workflow_call: jobs: fuzz: From 5dade0d7eb5d3d9119fef108bd1fb658dc1b37a6 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:10:28 +0200 Subject: [PATCH 07/21] project structure --- .github/actions/build_and_test/action.yml | 38 +++++++++++++++++ .../actions/build_and_test/build_and_test.yml | 42 ------------------- .github/actions/fuzz_tests/action.yml | 24 +++++++++++ .github/actions/fuzz_tests/fuzz_tests.yml | 33 --------------- .github/workflows/ci.yml | 16 ++++++- 5 files changed, 76 insertions(+), 77 deletions(-) create mode 100644 .github/actions/build_and_test/action.yml delete mode 100644 .github/actions/build_and_test/build_and_test.yml create mode 100644 .github/actions/fuzz_tests/action.yml delete mode 100644 .github/actions/fuzz_tests/fuzz_tests.yml diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml new file mode 100644 index 0000000..22a995c --- /dev/null +++ b/.github/actions/build_and_test/action.yml @@ -0,0 +1,38 @@ +name: Build and Test +description: Run build and test steps for the project + +runs: + using: composite + steps: + - name: Install Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + components: rustfmt, clippy + + - name: Cargo Format + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + - name: Clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features -- -D warnings + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --all-features + + - name: Test + uses: actions-rs/cargo@v1 + with: + command: test + args: -- --test-threads=1 + diff --git a/.github/actions/build_and_test/build_and_test.yml b/.github/actions/build_and_test/build_and_test.yml deleted file mode 100644 index 8bd6519..0000000 --- a/.github/actions/build_and_test/build_and_test.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build and Test - - -jobs: - build_and_test: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt, clippy - - - name: Cargo Format - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - - name: Clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-features -- -D warnings - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-features - - - name: Test - uses: actions-rs/cargo@v1 - with: - command: test - args: -- --test-threads=1 - diff --git a/.github/actions/fuzz_tests/action.yml b/.github/actions/fuzz_tests/action.yml new file mode 100644 index 0000000..1de75b4 --- /dev/null +++ b/.github/actions/fuzz_tests/action.yml @@ -0,0 +1,24 @@ +name: Smoke-Test Fuzz Targets +description: Run fuzz tests on the project + +runs: + using: composite + steps: + - name: Install Nightly Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: Install cargo-fuzz + uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-fuzz --version 0.13.0 + + - name: Run Fuzz Tests + shell: bash + working-directory: fuzz + run: cargo fuzz run fuzz_string --release -- -max_total_time=180 + diff --git a/.github/actions/fuzz_tests/fuzz_tests.yml b/.github/actions/fuzz_tests/fuzz_tests.yml deleted file mode 100644 index e856196..0000000 --- a/.github/actions/fuzz_tests/fuzz_tests.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Smoke-Test Fuzz Targets - - -jobs: - fuzz: - env: - CARGO_FUZZ_VERSION: 0.13.0 - FUZZ_TIME: 180 - - strategy: - matrix: - include: - - fuzz_target: fuzz_string - runs-on: ubuntu-latest - steps: - - name: Setup - uses: actions/checkout@v4 - - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: cargo-fuzz - - - uses: actions-rs/cargo@v1 - with: - command: install - args: cargo-fuzz --version ${{ env.CARGO_FUZZ_VERSION }} - - - name: Fuzz - working-directory: fuzz - run: cargo fuzz run ${{ matrix.fuzz_target }} --release -- -max_total_time=${{ env.FUZZ_TIME }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7665815..aacf742 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,21 @@ concurrency: jobs: build_and_test: name: Build and Test - uses: ./.github/actions/build_and_test/build_and_test.yml + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run Build and Test + uses: ./.github/actions/build_and_test fuzz_tests: name: Fuzz Tests - uses: ./.github/actions/fuzz_tests/fuzz_tests.yml + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run Fuzz Tests + uses: ./.github/actions/fuzz_tests From 123da8589f9d28d1186ad5814ac6251a87ff8659 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:12:54 +0200 Subject: [PATCH 08/21] fix --- .github/actions/build_and_test/action.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 22a995c..11f4735 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -17,12 +17,6 @@ runs: with: command: fmt args: -- --check - - - name: Clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-features -- -D warnings - name: Build uses: actions-rs/cargo@v1 From b215cf2e097239af93e7a32be2c0681cfd93445d Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:14:32 +0200 Subject: [PATCH 09/21] remove toolchain --- .github/actions/build_and_test/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 11f4735..975a3f8 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -8,7 +8,6 @@ runs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable override: true components: rustfmt, clippy From 71bbf38d219ebaff78b4301ed921ce29dc8952d0 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:26:39 +0200 Subject: [PATCH 10/21] ci --- .github/actions/build_and_test/action.yml | 7 ------- .github/actions/fuzz_tests/action.yml | 17 +++++++++++++++-- .github/workflows/ci.yml | 9 ++++++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 975a3f8..65613bb 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -4,13 +4,6 @@ description: Run build and test steps for the project runs: using: composite steps: - - name: Install Toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - override: true - components: rustfmt, clippy - - name: Cargo Format uses: actions-rs/cargo@v1 with: diff --git a/.github/actions/fuzz_tests/action.yml b/.github/actions/fuzz_tests/action.yml index 1de75b4..c68dee7 100644 --- a/.github/actions/fuzz_tests/action.yml +++ b/.github/actions/fuzz_tests/action.yml @@ -1,6 +1,19 @@ name: Smoke-Test Fuzz Targets description: Run fuzz tests on the project +inputs: + fuzz_target: + description: 'The fuzz target to run' + required: true + fuzz_time: + description: 'Maximum time in seconds to run fuzzing' + required: false + default: '180' + cargo_fuzz_version: + description: 'Version of cargo-fuzz to install' + required: false + default: '0.13.0' + runs: using: composite steps: @@ -15,10 +28,10 @@ runs: uses: actions-rs/cargo@v1 with: command: install - args: cargo-fuzz --version 0.13.0 + args: cargo-fuzz --version ${{ inputs.cargo_fuzz_version }} - name: Run Fuzz Tests shell: bash working-directory: fuzz - run: cargo fuzz run fuzz_string --release -- -max_total_time=180 + run: cargo fuzz run ${{ inputs.fuzz_target }} --release -- -max_total_time=${{ inputs.fuzz_time }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aacf742..3f25bef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,12 +18,19 @@ jobs: uses: ./.github/actions/build_and_test fuzz_tests: - name: Fuzz Tests + name: Fuzz Tests (${{ matrix.fuzz_target }}) runs-on: ubuntu-latest + strategy: + matrix: + fuzz_target: + - fuzz_string + # Add more fuzz targets here as needed steps: - name: Checkout repository uses: actions/checkout@v4 - name: Run Fuzz Tests uses: ./.github/actions/fuzz_tests + with: + fuzz_target: ${{ matrix.fuzz_target }} From 0669e74be4f02a57b71b42251bc9b56db30776b2 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:29:30 +0200 Subject: [PATCH 11/21] ci --- .github/actions/build_and_test/action.yml | 5 +++++ Cargo.toml | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 65613bb..17d0383 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -4,6 +4,11 @@ description: Run build and test steps for the project runs: using: composite steps: + - name: Install Toolchain + uses: actions-rs/toolchain@v1 + with: + components: rustfmt + - name: Cargo Format uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 06ef9f9..9332c82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,4 @@ half = "2.0.0" mockalloc = "0.1.2" ctor = "0.1.16" rand = "0.8.4" -cargo-fuzz = "0.13.0" -ijson-fuzz = { path = "fuzz" } From c6dabbd7481aa67432d742390165dbbbe7d08e35 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 15:33:58 +0200 Subject: [PATCH 12/21] ci --- .github/actions/build_and_test/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 17d0383..1c66265 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -7,6 +7,7 @@ runs: - name: Install Toolchain uses: actions-rs/toolchain@v1 with: + toolchain: "1.88" components: rustfmt - name: Cargo Format From 0a54aa645b990a69cdf067bb9c042aac0140a016 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:02:02 +0200 Subject: [PATCH 13/21] fix --- .github/actions/build_and_test/action.yml | 2 +- .github/actions/fuzz_tests/action.yml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 1c66265..0798d7a 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -20,7 +20,7 @@ runs: uses: actions-rs/cargo@v1 with: command: build - args: --release --all-features + args: --release - name: Test uses: actions-rs/cargo@v1 diff --git a/.github/actions/fuzz_tests/action.yml b/.github/actions/fuzz_tests/action.yml index c68dee7..95c7b09 100644 --- a/.github/actions/fuzz_tests/action.yml +++ b/.github/actions/fuzz_tests/action.yml @@ -17,13 +17,6 @@ inputs: runs: using: composite steps: - - name: Install Nightly Toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - - name: Install cargo-fuzz uses: actions-rs/cargo@v1 with: From 543065b0722d18b31175517fd2747b54b7194a17 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:06:03 +0200 Subject: [PATCH 14/21] test --- .github/actions/build_and_test/action.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 0798d7a..31502db 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -17,10 +17,11 @@ runs: args: -- --check - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release + #uses: actions-rs/cargo@v1 + # with: + # command: build + # args: --release + run: cargo build - name: Test uses: actions-rs/cargo@v1 From 76e1adc4fb1e276fce6d2e5bdbb4cd8e67f53b68 Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:14:02 +0200 Subject: [PATCH 15/21] fix --- .github/actions/build_and_test/action.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 31502db..08bdf35 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -17,10 +17,6 @@ runs: args: -- --check - name: Build - #uses: actions-rs/cargo@v1 - # with: - # command: build - # args: --release run: cargo build - name: Test From e864539017cd7c180d230eedeac59eaefa457a5b Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:17:35 +0200 Subject: [PATCH 16/21] fix --- .github/actions/build_and_test/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/build_and_test/action.yml b/.github/actions/build_and_test/action.yml index 08bdf35..8dcbc12 100644 --- a/.github/actions/build_and_test/action.yml +++ b/.github/actions/build_and_test/action.yml @@ -17,6 +17,7 @@ runs: args: -- --check - name: Build + shell: bash run: cargo build - name: Test From ad754fb1705523c8c6a88241611a58291f8296eb Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:31:39 +0200 Subject: [PATCH 17/21] change to randomise json de --- .github/workflows/ci.yml | 2 +- fuzz/Cargo.toml | 4 +-- fuzz/fuzz_targets/fuzz_json_de.rs | 55 +++++++++++++++++++++++++++++++ fuzz/fuzz_targets/fuzz_string.rs | 13 -------- 4 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 fuzz/fuzz_targets/fuzz_json_de.rs delete mode 100644 fuzz/fuzz_targets/fuzz_string.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f25bef..f690705 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: fuzz_target: - - fuzz_string + - fuzz_json_de # Add more fuzz targets here as needed steps: - name: Checkout repository diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 7fa911e..09cd0b9 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -17,8 +17,8 @@ serde_json = { workspace = true } path = ".." [[bin]] -name = "fuzz_string" -path = "fuzz_targets/fuzz_string.rs" +name = "fuzz_json_de" +path = "fuzz_targets/fuzz_json_de.rs" test = false doc = false bench = false diff --git a/fuzz/fuzz_targets/fuzz_json_de.rs b/fuzz/fuzz_targets/fuzz_json_de.rs new file mode 100644 index 0000000..4accf66 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_json_de.rs @@ -0,0 +1,55 @@ +#![no_main] + +use arbitrary::Arbitrary; +use ijson::IValue; +use libfuzzer_sys::fuzz_target; +use serde::Deserialize; +use std::collections::HashMap; + +#[derive(Arbitrary, Debug)] +enum JsonValue { + Null, + Bool(bool), + Number(f64), + String(String), + Array(Vec), + Object(HashMap), +} + +impl JsonValue { + fn to_json_string(&self) -> String { + match self { + JsonValue::Null => "null".to_string(), + JsonValue::Bool(b) => b.to_string(), + JsonValue::Number(n) => { + if n.is_finite() { + n.to_string() + } else { + "0".to_string() + } + } + JsonValue::String(s) => serde_json::to_string(s).unwrap_or_else(|_| "\"\"".to_string()), + JsonValue::Array(arr) => { + let items: Vec = arr.iter().map(|v| v.to_json_string()).collect(); + format!("[{}]", items.join(",")) + } + JsonValue::Object(obj) => { + let items: Vec = obj + .iter() + .map(|(k, v)| { + let key = serde_json::to_string(k).unwrap_or_else(|_| "\"\"".to_string()); + format!("{}:{}", key, v.to_json_string()) + }) + .collect(); + format!("{{{}}}", items.join(",")) + } + } + } +} + +fuzz_target!(|value: JsonValue| { + let json_string = value.to_json_string(); + println!("json_string: {}", json_string); + let mut deserializer = serde_json::Deserializer::from_str(&json_string); + let _ = IValue::deserialize(&mut deserializer); +}); diff --git a/fuzz/fuzz_targets/fuzz_string.rs b/fuzz/fuzz_targets/fuzz_string.rs deleted file mode 100644 index 32d0254..0000000 --- a/fuzz/fuzz_targets/fuzz_string.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_main] - -use ijson::IValue; -use libfuzzer_sys::fuzz_target; -use serde::Deserialize; - -fuzz_target!(|data: &str| { - if data.is_empty() { - return; - } - let mut deserializer = serde_json::Deserializer::from_str(data); - let _ = IValue::deserialize(&mut deserializer); -}); From 39813023e43963a99cc76fa11842ee748f1a0e7c Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:32:34 +0200 Subject: [PATCH 18/21] remove print --- fuzz/fuzz_targets/fuzz_json_de.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/fuzz/fuzz_targets/fuzz_json_de.rs b/fuzz/fuzz_targets/fuzz_json_de.rs index 4accf66..4587c7c 100644 --- a/fuzz/fuzz_targets/fuzz_json_de.rs +++ b/fuzz/fuzz_targets/fuzz_json_de.rs @@ -49,7 +49,6 @@ impl JsonValue { fuzz_target!(|value: JsonValue| { let json_string = value.to_json_string(); - println!("json_string: {}", json_string); let mut deserializer = serde_json::Deserializer::from_str(&json_string); let _ = IValue::deserialize(&mut deserializer); }); From 19b5378742cd3ff16c87bc81d86812bc4e262b5c Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:34:56 +0200 Subject: [PATCH 19/21] fix strings --- fuzz/fuzz_targets/fuzz_json_de.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fuzz/fuzz_targets/fuzz_json_de.rs b/fuzz/fuzz_targets/fuzz_json_de.rs index 4587c7c..2f6f0ea 100644 --- a/fuzz/fuzz_targets/fuzz_json_de.rs +++ b/fuzz/fuzz_targets/fuzz_json_de.rs @@ -28,7 +28,7 @@ impl JsonValue { "0".to_string() } } - JsonValue::String(s) => serde_json::to_string(s).unwrap_or_else(|_| "\"\"".to_string()), + JsonValue::String(s) => s.clone(), JsonValue::Array(arr) => { let items: Vec = arr.iter().map(|v| v.to_json_string()).collect(); format!("[{}]", items.join(",")) @@ -37,7 +37,7 @@ impl JsonValue { let items: Vec = obj .iter() .map(|(k, v)| { - let key = serde_json::to_string(k).unwrap_or_else(|_| "\"\"".to_string()); + let key = k.clone(); format!("{}:{}", key, v.to_json_string()) }) .collect(); @@ -49,6 +49,7 @@ impl JsonValue { fuzz_target!(|value: JsonValue| { let json_string = value.to_json_string(); + println!("json_string: {}", json_string); let mut deserializer = serde_json::Deserializer::from_str(&json_string); let _ = IValue::deserialize(&mut deserializer); }); From 44b5a5b94b27e4adf1e6bae09ddea4d7c4108d1b Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:35:45 +0200 Subject: [PATCH 20/21] remove print, again --- fuzz/fuzz_targets/fuzz_json_de.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/fuzz/fuzz_targets/fuzz_json_de.rs b/fuzz/fuzz_targets/fuzz_json_de.rs index 2f6f0ea..2bf61de 100644 --- a/fuzz/fuzz_targets/fuzz_json_de.rs +++ b/fuzz/fuzz_targets/fuzz_json_de.rs @@ -49,7 +49,6 @@ impl JsonValue { fuzz_target!(|value: JsonValue| { let json_string = value.to_json_string(); - println!("json_string: {}", json_string); let mut deserializer = serde_json::Deserializer::from_str(&json_string); let _ = IValue::deserialize(&mut deserializer); }); From b362ba74d7ce9eeca9e171b8845d5034136a3fca Mon Sep 17 00:00:00 2001 From: avivdavid23 Date: Thu, 13 Nov 2025 16:45:35 +0200 Subject: [PATCH 21/21] fix --- fuzz/fuzz_targets/fuzz_json_de.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuzz/fuzz_targets/fuzz_json_de.rs b/fuzz/fuzz_targets/fuzz_json_de.rs index 2bf61de..1592e59 100644 --- a/fuzz/fuzz_targets/fuzz_json_de.rs +++ b/fuzz/fuzz_targets/fuzz_json_de.rs @@ -28,7 +28,7 @@ impl JsonValue { "0".to_string() } } - JsonValue::String(s) => s.clone(), + JsonValue::String(s) => format!("\"{}\"", s), JsonValue::Array(arr) => { let items: Vec = arr.iter().map(|v| v.to_json_string()).collect(); format!("[{}]", items.join(",")) @@ -38,7 +38,7 @@ impl JsonValue { .iter() .map(|(k, v)| { let key = k.clone(); - format!("{}:{}", key, v.to_json_string()) + format!("\"{}\":{}", key, v.to_json_string()) }) .collect(); format!("{{{}}}", items.join(","))