Skip to content
Open
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
28 changes: 28 additions & 0 deletions .github/actions/build_and_test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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:
toolchain: "1.88"
components: rustfmt

- name: Cargo Format
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

- name: Build
shell: bash
run: cargo build

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: -- --test-threads=1

30 changes: 30 additions & 0 deletions .github/actions/fuzz_tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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:
- name: Install cargo-fuzz
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-fuzz --version ${{ inputs.cargo_fuzz_version }}

- name: Run Fuzz Tests
shell: bash
working-directory: fuzz
run: cargo fuzz run ${{ inputs.fuzz_target }} --release -- -max_total_time=${{ inputs.fuzz_time }}

36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_and_test:
name: Build and Test
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 (${{ matrix.fuzz_target }})
runs-on: ubuntu-latest
strategy:
matrix:
fuzz_target:
- fuzz_json_de
# 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 }}

175 changes: 0 additions & 175 deletions .github/workflows/toolchain.yml

This file was deleted.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
members = ["fuzz"]

[package]
name = "ijson"
version = "0.1.3"
Expand All @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
24 changes: 24 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "ijson-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
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_json_de"
path = "fuzz_targets/fuzz_json_de.rs"
test = false
doc = false
bench = false
54 changes: 54 additions & 0 deletions fuzz/fuzz_targets/fuzz_json_de.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#![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<JsonValue>),
Object(HashMap<String, JsonValue>),
}

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) => format!("\"{}\"", s),
JsonValue::Array(arr) => {
let items: Vec<String> = arr.iter().map(|v| v.to_json_string()).collect();
format!("[{}]", items.join(","))
}
JsonValue::Object(obj) => {
let items: Vec<String> = obj
.iter()
.map(|(k, v)| {
let key = k.clone();
format!("\"{}\":{}", key, v.to_json_string())
})
.collect();
format!("{{{}}}", items.join(","))
}
}
}
}

fuzz_target!(|value: JsonValue| {
let json_string = value.to_json_string();
let mut deserializer = serde_json::Deserializer::from_str(&json_string);
let _ = IValue::deserialize(&mut deserializer);
});
2 changes: 2 additions & 0 deletions fuzz/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
Loading