Skip to content

Commit 37d285c

Browse files
committed
Run fuzzer in CI
As we do for `rust-bitcoin` run the fuzzer on each push and pull request. Requires: - Minor changes to fuzz target `encode_decode` to use current API - Installing hongfuzz without default dependencies (`arbitrary`)
1 parent bd4e8e2 commit 37d285c

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

.github/workflows/fuzz.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Fuzz
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
7+
fuzz:
8+
if: ${{ !github.event.act }}
9+
runs-on: ubuntu-20.04
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
fuzz_target: [decode_rnd, encode_decode]
14+
steps:
15+
- name: Install test dependencies
16+
run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
17+
- uses: actions/checkout@v2
18+
- uses: actions/cache@v2
19+
id: cache-fuzz
20+
with:
21+
path: |
22+
~/.cargo/bin
23+
fuzz/target
24+
target
25+
key: cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
26+
- name: Checkout Toolchain
27+
uses: dtolnay/rust-toolchain@stable
28+
- name: fuzz
29+
run: cd fuzz && ./fuzz.sh "${{ matrix.fuzz_target }}"
30+
- run: echo "${{ matrix.fuzz_target }}.rs" >executed_${{ matrix.fuzz_target }}
31+
- uses: actions/upload-artifact@v2
32+
with:
33+
name: executed_${{ matrix.fuzz_target }}
34+
path: executed_${{ matrix.fuzz_target }}
35+
36+
verify-execution:
37+
if: ${{ !github.event.act }}
38+
needs: fuzz
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: actions/download-artifact@v2
43+
- name: Display structure of downloaded files
44+
run: ls -R
45+
- run: find executed_* -type f -exec cat {} + | sort > executed
46+
- run: ls fuzz/fuzz_targets | sort > expected
47+
- run: diff expected executed

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ afl_fuzz = ["afl"]
1212
honggfuzz_fuzz = ["honggfuzz"]
1313

1414
[dependencies]
15-
honggfuzz = { version = "0.5", optional = true }
15+
honggfuzz = { version = "0.5", default-features = false, optional = true }
1616
afl = { version = "0.3", optional = true }
1717
libc = "0.2"
1818
bech32 = { path = ".." }

fuzz/fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
cargo install --force honggfuzz
3+
cargo install --force honggfuzz --no-default-features
44
for TARGET in fuzz_targets/*; do
55
FILENAME=$(basename $TARGET)
66
FILE="${FILENAME%.*}"

fuzz/fuzz_targets/encode_decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate bech32;
22

3-
use std::str::FromStr;
3+
use std::convert::TryFrom;
44

55
fn do_test(data: &[u8]) {
66
if data.len() < 1 {
@@ -19,7 +19,7 @@ fn do_test(data: &[u8]) {
1919

2020
let dp = data[hrp_end..]
2121
.iter()
22-
.map(|b| bech32::u5::try_from_u8(b % 32).unwrap())
22+
.map(|b| bech32::u5::try_from(b % 32).unwrap())
2323
.collect::<Vec<_>>();
2424

2525
let variant = if data[0] > 0x0f {

0 commit comments

Comments
 (0)