Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/fuzzing.yml
blob: c6a1e59675ae56a68ec5aaf206c27a319db6a8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
# SPDX-License-Identifier: LGPL-3.0-or-later

name: Fuzzing

# Each fuzz target reads input from outside: test specs, the project
# configuration, the runner's JSON and its command line. A pull request runs
# each for two minutes; every night each runs for thirty. The corpus each run
# grows is kept in the cache of the devel branch, so the next run starts from
# it, and a crash uploads its input. A crash input becomes a regression test.

on:
  push:
    branches: [devel]
  pull_request:
  schedule:
    - cron: '17 2 * * *'
  workflow_dispatch:

permissions:
  contents: read

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

jobs:
  fuzz:
    name: Fuzz ${{matrix.target}}
    runs-on: ubuntu-26.04
    timeout-minutes: 50
    strategy:
      fail-fast: false
      matrix:
        target: [TestSpecParser, ProjectConfig, RunnerJson, RunnerOptions]

    steps:
    - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
      with:
        persist-credentials: false

    - name: Install Clang, CMake and Ninja
      run: |
        sudo apt-get update
        sudo apt-get install -y clang cmake ninja-build

    - name: Configure
      run: |
        cmake -S . -B build-fuzzers -GNinja \
              -DCMAKE_BUILD_TYPE=RelWithDebInfo \
              -DCMAKE_CXX_COMPILER=clang++ \
              -DCMAKE_CXX_FLAGS="-fsanitize=fuzzer-no-link,address,undefined -fno-sanitize-recover=undefined" \
              -DCATCH3_DEVELOPMENT_BUILD=ON \
              -DCATCH3_BUILD_FUZZERS=ON \
              -DCATCH3_BUILD_TESTING=OFF \
              -DCATCH3_BUILD_EXAMPLES=OFF \
              -DCATCH3_BUILD_EXTRA_TESTS=OFF \
              -DCATCH3_ENABLE_WERROR=OFF \
              -DBUILD_TESTING=OFF

    - name: Build
      run: cmake --build build-fuzzers --target fuzz_${{matrix.target}}

    - name: Restore the corpus
      uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
      with:
        path: corpus/${{matrix.target}}
        key: fuzz-corpus-${{matrix.target}}-${{github.run_id}}
        restore-keys: fuzz-corpus-${{matrix.target}}-

    - name: Fuzz
      env:
        TARGET: ${{matrix.target}}
        SECONDS_PER_TARGET: ${{ github.event_name == 'schedule' && 1800 || 120 }}
        ASAN_OPTIONS: detect_leaks=1:abort_on_error=1
        UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
      run: |
        mkdir -p "corpus/$TARGET" crashes
        binary=$(find build-fuzzers -type f -name "fuzz_$TARGET" -perm -u+x | head -n 1)
        "$binary" -max_total_time="$SECONDS_PER_TARGET" -timeout=10 -rss_limit_mb=2048 \
                  -artifact_prefix=crashes/ -print_final_stats=1 "corpus/$TARGET"

    - name: Upload crash inputs
      if: failure()
      uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
      with:
        name: fuzz-crashes-${{matrix.target}}
        path: crashes/
        if-no-files-found: ignore

    - name: Keep the corpus
      if: success() && github.event_name != 'pull_request'
      uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
      with:
        path: corpus/${{matrix.target}}
        key: fuzz-corpus-${{matrix.target}}-${{github.run_id}}