Repository: alex/rust-asn1 (language: rust)

Issue:
Consider setting up clusterfuzzlite
https://security.googleblog.com/2021/11/clusterfuzzlite-continuous-fuzzing-for.html

This may be better than the ad-hoc fuzzing we do in CI.


Discussion / hints:

Fix patch:
diff --git a/.clusterfuzzlite/Dockerfile b/.clusterfuzzlite/Dockerfile
new file mode 100644
index 0000000..cc52af4
--- /dev/null
+++ b/.clusterfuzzlite/Dockerfile
@@ -0,0 +1,4 @@
+FROM gcr.io/oss-fuzz-base/base-builder-rust:v1
+COPY . $SRC/rust-asn1
+WORKDIR rust-asn1
+COPY .clusterfuzzlite/build.sh $SRC/
diff --git a/.clusterfuzzlite/build.sh b/.clusterfuzzlite/build.sh
new file mode 100755
index 0000000..19afeb6
--- /dev/null
+++ b/.clusterfuzzlite/build.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -eu
+
+cargo fuzz build -O --debug-assertions
+
+FUZZ_TARGET_OUTPUT_DIR=fuzz/target/x86_64-unknown-linux-gnu/release
+for f in fuzz/fuzz_targets/*.rs
+do
+    FUZZ_TARGET_NAME=$(basename ${f%.*})
+    cp $FUZZ_TARGET_OUTPUT_DIR/$FUZZ_TARGET_NAME $OUT/
+done
+
diff --git a/.clusterfuzzlite/project.yaml b/.clusterfuzzlite/project.yaml
new file mode 100644
index 0000000..22761ba
--- /dev/null
+++ b/.clusterfuzzlite/project.yaml
@@ -0,0 +1,1 @@
+language: rust
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8b5b801..100cfe9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -162,39 +162,3 @@ jobs:
           if coverage < 99.9:
               raise ValueError(f"Coverage too low: {coverage}")
         shell: python
-
-  fuzz:
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        RUST:
-          - nightly
-
-    steps:
-      - uses: actions/checkout@v3.0.2
-        with:
-          persist-credentials: false
-
-      - uses: dtolnay/rust-toolchain@1ce4a7352a1efe5dede2e52c75512b34256e4f44
-        with:
-          toolchain: ${{ matrix.RUST }}
-
-      - uses: actions/cache@v3.0.6
-        id: cargo-cache
-        with:
-          path: |
-            ~/.cargo/bin/
-            ~/.cargo/registry/index/
-            ~/.cargo/registry/cache/
-            ~/.cargo/git/db/
-            target/
-          key: ${{ runner.os }}-cargo-3-${{ hashFiles('**/Cargo.toml') }}
-
-      - run: cargo install cargo-fuzz
-        if: steps.cargo-cache.outputs.cache-hit != 'true'
-
-      - run: cargo fuzz run --all-features fuzz_asn1_parse -- -max_total_time=30
-
-      # On main we fuzz for 30 minutes, but only 30 seconds on PRs.
-      - run: cargo fuzz run --all-features fuzz_asn1_parse -- -max_total_time=1800
-        if: github.event_name == 'push' && github.ref == 'refs/heads/main'
diff --git a/.github/workflows/fuzz-build.yml b/.github/workflows/fuzz-build.yml
new file mode 100644
index 0000000..3acc30b
--- /dev/null
+++ b/.github/workflows/fuzz-build.yml
@@ -0,0 +1,24 @@
+name: ClusterFuzzLite continuous builds
+on:
+  push:
+    branches:
+      - main
+
+permissions: read-all
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        sanitizer:
+          - address
+    steps:
+      - name: Build Fuzzers (${{ matrix.sanitizer }})
+        id: build
+        uses: google/clusterfuzzlite/actions/build_fuzzers@90ae9e93faff65e30464feb0f5c0ea48a66d4663
+        with:
+          language: rust
+          sanitizer: ${{ matrix.sanitizer }}
+          upload-build: true
diff --git a/.github/workflows/fuzz-cron.yml b/.github/workflows/fuzz-cron.yml
new file mode 100644
index 0000000..b1fb55a
--- /dev/null
+++ b/.github/workflows/fuzz-cron.yml
@@ -0,0 +1,32 @@
+name: ClusterFuzzLite batch fuzzing
+on:
+  # We could also consider adding a cron to run regularly.
+  push:
+    branches:
+      - main
+
+permissions: read-all
+
+jobs:
+  cron:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        sanitizer:
+          - address
+    steps:
+      - name: Build Fuzzers (${{ matrix.sanitizer }})
+        id: build
+        uses: google/clusterfuzzlite/actions/build_fuzzers@90ae9e93faff65e30464feb0f5c0ea48a66d4663
+        with:
+          language: rust
+          sanitizer: ${{ matrix.sanitizer }}
+      - name: Run Fuzzers (${{ matrix.sanitizer }})
+        id: run
+        uses: google/clusterfuzzlite/actions/run_fuzzers@90ae9e93faff65e30464feb0f5c0ea48a66d4663
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          fuzz-seconds: 3600
+          mode: 'batch'
+          sanitizer: ${{ matrix.sanitizer }}
diff --git a/.github/workflows/fuzz-pr.yml b/.github/workflows/fuzz-pr.yml
new file mode 100644
index 0000000..d6f4958
--- /dev/null
+++ b/.github/workflows/fuzz-pr.yml
@@ -0,0 +1,33 @@
+name: ClusterFuzzLite PR fuzzing
+on:
+  pull_request: {}
+
+permissions: read-all
+
+jobs:
+  pr:
+    runs-on: ubuntu-latest
+    concurrency:
+      group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }}
+      cancel-in-progress: true
+    strategy:
+      fail-fast: false
+      matrix:
+        sanitizer:
+          - address
+    steps:
+      - name: Build Fuzzers (${{ matrix.sanitizer }})
+        id: build
+        uses: google/clusterfuzzlite/actions/build_fuzzers@90ae9e93faff65e30464feb0f5c0ea48a66d4663
+        with:
+          language: rust
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          sanitizer: ${{ matrix.sanitizer }}
+      - name: Run Fuzzers (${{ matrix.sanitizer }})
+        id: run
+        uses: google/clusterfuzzlite/actions/run_fuzzers@90ae9e93faff65e30464feb0f5c0ea48a66d4663
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          fuzz-seconds: 30
+          mode: 'code-change'
+          sanitizer: ${{ matrix.sanitizer }}
diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml
index cc0e334..f6a725f 100644
--- a/fuzz/Cargo.toml
+++ b/fuzz/Cargo.toml
@@ -10,7 +10,7 @@ cargo-fuzz = true
 
 [dependencies]
 asn1 = { path = ".." }
-libfuzzer-sys = "0.3"
+libfuzzer-sys = "0.4"
 
 
 # Prevent this from interfering with workspaces


Test patch: