|
| 1 | +name: Fuzz Python Env Comparison |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - .github/workflows/fuzz-python-env-comparison.yml |
| 8 | + - .github/workflows/fuzz.yml |
| 9 | + - fuzz/fuzz_targets/validate_with_python.rs |
| 10 | + - Cargo.toml |
| 11 | + - Cargo.lock |
| 12 | + - fuzz/Cargo.toml |
| 13 | + - fuzz/Cargo.lock |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + duration: |
| 17 | + description: Fuzzing duration in seconds |
| 18 | + required: false |
| 19 | + default: "1800" |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +env: |
| 25 | + CARGO_TERM_COLOR: always |
| 26 | + RUST_BACKTRACE: 1 |
| 27 | + |
| 28 | +jobs: |
| 29 | + compare-python-env: |
| 30 | + name: Compare Python env policy (${{ matrix.name }}) |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 45 |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + include: |
| 37 | + - name: inherit |
| 38 | + env_policy: inherit |
| 39 | + - name: strip-setup-python |
| 40 | + env_policy: strip_setup_python |
| 41 | + - name: strip-setup-python-and-ld-library-path |
| 42 | + env_policy: strip_setup_python_and_ld_library_path |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Install Rust toolchain |
| 49 | + uses: dtolnay/rust-toolchain@0f1b44df7e9cbb178d781a242338dfa5e243ad7f |
| 50 | + with: |
| 51 | + toolchain: nightly |
| 52 | + |
| 53 | + - name: Install Python |
| 54 | + uses: actions/setup-python@v5 |
| 55 | + with: |
| 56 | + python-version: "3.11" |
| 57 | + |
| 58 | + - name: Install cargo-fuzz |
| 59 | + run: cargo install cargo-fuzz |
| 60 | + |
| 61 | + - name: Cache fuzz corpus |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: fuzz/corpus/validate_with_python |
| 65 | + key: fuzz-python-env-compare-${{ github.sha }} |
| 66 | + restore-keys: | |
| 67 | + fuzz-python-env-compare- |
| 68 | + fuzz-corpus-validate-python- |
| 69 | +
|
| 70 | + - name: Determine fuzzing duration |
| 71 | + id: duration |
| 72 | + env: |
| 73 | + EVENT_NAME: ${{ github.event_name }} |
| 74 | + INPUT_DURATION: ${{ github.event.inputs.duration }} |
| 75 | + run: | |
| 76 | + duration=1800 |
| 77 | + if [ "$EVENT_NAME" = "workflow_dispatch" ]; then |
| 78 | + case "$INPUT_DURATION" in |
| 79 | + ''|*[!0-9]*) |
| 80 | + echo "::error::workflow_dispatch input 'duration' must be a whole number of seconds" |
| 81 | + exit 1 |
| 82 | + ;; |
| 83 | + esac |
| 84 | + duration="$INPUT_DURATION" |
| 85 | + fi |
| 86 | + printf 'duration=%s\n' "$duration" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Report Python environment |
| 89 | + env: |
| 90 | + PICKLE_FUZZ_PYTHON_ENV_POLICY: ${{ matrix.env_policy }} |
| 91 | + run: | |
| 92 | + echo "policy=$PICKLE_FUZZ_PYTHON_ENV_POLICY" |
| 93 | + python3 --version |
| 94 | + env | sort | grep -E '^(pythonLocation|PKG_CONFIG_PATH|Python_ROOT_DIR|Python2_ROOT_DIR|Python3_ROOT_DIR|LD_LIBRARY_PATH)=' || true |
| 95 | +
|
| 96 | + - name: Run Python-validation fuzzing |
| 97 | + env: |
| 98 | + FUZZ_DURATION: ${{ steps.duration.outputs.duration }} |
| 99 | + PICKLE_FUZZ_PYTHON_ENV_POLICY: ${{ matrix.env_policy }} |
| 100 | + run: | |
| 101 | + cargo fuzz run validate_with_python -- \ |
| 102 | + -max_total_time="$FUZZ_DURATION" \ |
| 103 | + -print_final_stats=1 \ |
| 104 | + -verbosity=1 |
| 105 | + continue-on-error: true |
| 106 | + |
| 107 | + - name: Check for crashes |
| 108 | + if: always() |
| 109 | + run: | |
| 110 | + if [ -d "fuzz/artifacts/validate_with_python" ]; then |
| 111 | + if ls fuzz/artifacts/validate_with_python/crash-* 2>/dev/null || \ |
| 112 | + ls fuzz/artifacts/validate_with_python/timeout-* 2>/dev/null || \ |
| 113 | + ls fuzz/artifacts/validate_with_python/oom-* 2>/dev/null; then |
| 114 | + echo "::error::Fuzzing found crashes for policy ${{ matrix.env_policy }}!" |
| 115 | + ls -la fuzz/artifacts/validate_with_python/ |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + if ls fuzz/artifacts/validate_with_python/leak-* 2>/dev/null; then |
| 119 | + echo "::warning::Memory leaks detected for policy ${{ matrix.env_policy }}" |
| 120 | + ls -la fuzz/artifacts/validate_with_python/leak-* |
| 121 | + fi |
| 122 | + else |
| 123 | + echo "::error::Fuzzing did not create fuzz/artifacts/validate_with_python. cargo fuzz likely failed before execution." |
| 124 | + exit 1 |
| 125 | + fi |
| 126 | +
|
| 127 | + - name: Upload fuzz artifacts |
| 128 | + if: always() |
| 129 | + uses: actions/upload-artifact@v4 |
| 130 | + with: |
| 131 | + name: fuzz-python-env-${{ matrix.name }} |
| 132 | + path: fuzz/artifacts/validate_with_python/ |
| 133 | + if-no-files-found: ignore |
0 commit comments