Skip to content

Commit

Permalink
Draft: Add fuzzing to wavedrom
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite committed Jul 4, 2023
1 parent f18c3b8 commit d6bd83d
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ cd ./tests
./run [path/to/skin.json5]
```

## Fuzzing

This project is fuzzed with [`cargo-fuzz`][cargo-fuzz]. This improves the
stability of the project.

```bash
cargo +nightly fuzz run wavejson-render
```

## MSRV

This crate currently only compiles with Rust 1.70. To select that version use:
Expand Down Expand Up @@ -83,4 +92,5 @@ Licensed under a [MIT License](./LICENSE). The demo website utilizes icons from
[cli]: ./wavedrom-cli
[mdbook-wavedrom]: ./mdbook-wavedrom
[dtd]: https://en.wikipedia.org/wiki/Digital_timing_diagram
[book]: https://coastalwhite.github.io/wavedrom-rs
[book]: https://coastalwhite.github.io/wavedrom-rs
[cargo-fuzz]: https://github.com/rust-fuzz/cargo-fuzz
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
301 changes: 301 additions & 0 deletions fuzz/Cargo.lock

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

28 changes: 28 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "wavedrom-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.wavedrom]
path = "../wavedrom"
features = ["arbitrary"]

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "wavejson-render"
path = "fuzz_targets/wavejson_render.rs"
test = false
doc = false
16 changes: 16 additions & 0 deletions fuzz/fuzz_targets/wavejson_render.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

use wavedrom::wavejson::WaveJson;
use wavedrom::Figure;

fuzz_target!(|data: WaveJson| {
let figure = Figure::from(data);

let Figure::Signal(figure) = figure;

let assembled = figure.assemble();
let mut writer = Vec::new();
let _ = assembled.write_svg(&mut writer);
});
5 changes: 5 additions & 0 deletions wavedrom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ optional = true
version = "1.0"
optional = true

[dependencies.arbitrary]
version = "1.3.0"
optional = true
features = ["derive"]

[features]
default = ["json5", "embed_font", "skins"]
embed_font = ["dep:ttf-parser"]
Expand Down
1 change: 1 addition & 0 deletions wavedrom/src/wavejson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::Figure;
pub mod signal;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
pub enum WaveJson {
Signal(SignalJson),
Expand Down
Loading

0 comments on commit d6bd83d

Please sign in to comment.