Skip to content

Commit 8a9537c

Browse files
authored
Improve fuzzing (#129)
Add targets for fuzzing properties, implementation correctness, and algorithm properties. Add binaries for debug and analysis. Also add scripts for convenience.
1 parent 27a68f4 commit 8a9537c

26 files changed

+822
-350
lines changed

.github/workflows/ci.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ jobs:
6161
- name: cd nostd && cargo +nightly clippy -- --deny=warnings
6262
run: cargo +nightly clippy -- --deny=warnings
6363
working-directory: nostd
64+
- name: cd lib/fuzz && cargo +nightly clippy --lib --examples -- --deny=warnings
65+
run: cargo +nightly clippy --lib --examples -- --deny=warnings
66+
working-directory: lib/fuzz
6467
- name: cd lib/fuzz && cargo +nightly clippy -- --deny=warnings
68+
env:
69+
RUSTFLAGS: --cfg=fuzzing
6570
run: cargo +nightly clippy -- --deny=warnings
6671
working-directory: lib/fuzz
6772
- name: cd lib && cargo +nightly build
@@ -103,7 +108,12 @@ jobs:
103108
- name: cd nostd && cargo +nightly build --release
104109
run: cargo +nightly build --release
105110
working-directory: nostd
111+
- name: cd lib/fuzz && cargo +nightly build --lib --examples
112+
run: cargo +nightly build --lib --examples
113+
working-directory: lib/fuzz
106114
- name: cd lib/fuzz && cargo +nightly build
115+
env:
116+
RUSTFLAGS: --cfg=fuzzing
107117
run: cargo +nightly build
108118
working-directory: lib/fuzz
109119
- name: cd cmp && cargo +nightly build
@@ -128,8 +138,8 @@ jobs:
128138
- name: cd nostd && cargo +nightly run --release --features=alloc
129139
run: cargo +nightly run --release --features=alloc
130140
working-directory: nostd
131-
- name: cd lib/fuzz && cargo +nightly test
132-
run: cargo +nightly test
141+
- name: cd lib/fuzz && cargo +nightly test --lib
142+
run: cargo +nightly test --lib
133143
working-directory: lib/fuzz
134144
- name: cd cmp && cargo +nightly test
135145
run: cargo +nightly test

lib/fuzz/Cargo.toml

+34-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.0.0"
44
authors = ["Automatically generated"]
55
publish = false
66
edition = "2021"
7-
rust-version = "1.81"
87

98
[package.metadata]
109
cargo-fuzz = true
@@ -13,20 +12,42 @@ cargo-fuzz = true
1312
data-encoding = { path = ".." }
1413
libfuzzer-sys = "0.4.3"
1514

15+
# Fuzz targets organization based on prefix:
16+
# - fuzz_FOO: FOO holds for the fuzzing tools (property testing)
17+
# - impl_FOO: FOO is correctly implemented (differential testing)
18+
# - spec_FOO: FOO holds for the specification (property testing)
19+
20+
[[bin]]
21+
name = "fuzz_any_spec"
22+
path = "fuzz_targets/fuzz_any_spec.rs"
23+
24+
[[bin]]
25+
name = "impl_encode"
26+
path = "fuzz_targets/impl_encode.rs"
27+
28+
[[bin]]
29+
name = "impl_decode"
30+
path = "fuzz_targets/impl_decode.rs"
31+
32+
[[bin]]
33+
name = "impl_new_encoder"
34+
path = "fuzz_targets/impl_new_encoder.rs"
35+
1636
[[bin]]
17-
name = "round_trip"
18-
path = "fuzz_targets/round_trip.rs"
19-
test = false
20-
doc = false
37+
name = "impl_encode_write_buffer"
38+
path = "fuzz_targets/impl_encode_write_buffer.rs"
2139

2240
[[bin]]
23-
name = "encoder"
24-
path = "fuzz_targets/encoder.rs"
25-
test = false
26-
doc = false
41+
name = "spec_spec_base"
42+
path = "fuzz_targets/spec_spec_base.rs"
2743

2844
[[bin]]
29-
name = "encode_write"
30-
path = "fuzz_targets/encode_write.rs"
31-
test = false
32-
doc = false
45+
name = "spec_encode_decode"
46+
path = "fuzz_targets/spec_encode_decode.rs"
47+
48+
[[bin]]
49+
name = "spec_decode_encode"
50+
path = "fuzz_targets/spec_decode_encode.rs"
51+
52+
[lints.rust]
53+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }

lib/fuzz/analyze.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cargo run --manifest-path=fuzz/Cargo.toml --release --example=analyze -- "$@"

lib/fuzz/compact.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
for target in $(cargo fuzz list); do
4+
cargo fuzz cmin $target
5+
done

lib/fuzz/debug.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
cargo run --manifest-path=fuzz/Cargo.toml --example=debug -- "$1"

0 commit comments

Comments
 (0)