### Set Up Virtual Environment and Install Dependencies Source: https://github.com/google/clusterfuzzlite/blob/main/docs/developing_clusterfuzzlite.md Create a Python virtual environment and install ClusterFuzzLite and development dependencies. ```bash python3 -m venv .venv source .venv/bin/activate # Install ClusterFuzzLite dependencies. pip install -r infra/cifuzz/requirements.txt # Install development requirements. pip install -r infra/ci/requirements.txt ``` -------------------------------- ### Install Ruby Dependencies Source: https://github.com/google/clusterfuzzlite/blob/main/docs/README.md Installs Ruby, Bundler, and project dependencies. Ensure you have Ruby and Bundler installed before running these commands. ```bash $ sudo apt install ruby bundler $ bundle config set path 'vendor/bundle' $ bundle install ``` -------------------------------- ### Build and install Python project with build.sh Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/python_lang.md Use 'pip3 install .' in your build.sh script to build and install the project, which is essential for projects with C extensions. ```shell # Build and install project (using current CFLAGS, CXXFLAGS). This is required # for projects with C extensions so that they're built with the proper flags. pip3 install . ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/google/clusterfuzzlite/blob/main/docs/README.md Serves the documentation site locally using Jekyll. This command requires the project dependencies to be installed first. ```bash $ bundle exec jekyll serve ``` -------------------------------- ### Java/JVM Dockerfile for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Dockerfile setup for Java/JVM projects using ClusterFuzzLite. It installs Maven and copies the project and build script. ```dockerfile # .clusterfuzzlite/Dockerfile FROM gcr.io/oss-fuzz-base/base-builder-jvm RUN apt-get update && apt-get install -y maven COPY . $SRC/myproject WORKDIR $SRC/myproject COPY .clusterfuzzlite/build.sh $SRC/ ``` -------------------------------- ### Use Swift Base Builder in Dockerfile Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/swift.md Ensure your Dockerfile starts with 'FROM gcr.io/oss-fuzz-base/base-builder-swift' for Swift projects. ```dockerfile FROM gcr.io/oss-fuzz-base/base-builder-swift ``` -------------------------------- ### Install Hypothesis for Python fuzzing Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/python_lang.md Install the Hypothesis library in your Dockerfile using 'pip3 install hypothesis' to enable property-based testing for fuzzing. ```shell RUN pip3 install hypothesis ``` -------------------------------- ### Go Dockerfile for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Dockerfile setup for Go projects using ClusterFuzzLite. It clones the repository and copies the build script. ```dockerfile # .clusterfuzzlite/Dockerfile FROM gcr.io/oss-fuzz-base/base-builder-go RUN git clone --depth 1 https://github.com/miekg/dns $SRC/dns WORKDIR $SRC/dns COPY .clusterfuzzlite/build.sh $SRC/ ``` -------------------------------- ### Example build.sh Script for Expat Project Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build_integration.md Builds the project using ClusterFuzzLite's compiler flags and links fuzz targets with libFuzzer. Place fuzz target binaries in the $OUT directory. Optionally copy dictionaries and options files. ```bash #!/bin/bash -eu ./buildconf.sh # configure scripts usually use correct environment variables. ./configure make clean make -j$(nproc) all $CXX $CXXFLAGS -std=c++11 -Ilib/ \ $SRC/parse_fuzzer.cc -o $OUT/parse_fuzzer \ $LIB_FUZZING_ENGINE .libs/libexpat.a # Optional: Copy dictionaries and options files. cp $SRC/*.dict $SRC/*.options $OUT/ ``` -------------------------------- ### Install Maven in Dockerfile Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/jvm_lang.md Add this line to your Dockerfile to install Maven if your JVM project uses it for building. ```docker RUN apt-get update && apt-get install -y maven ``` -------------------------------- ### Python Dockerfile for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Dockerfile setup for Python projects using ClusterFuzzLite. It installs project dependencies and prepares fuzzers using pyinstaller. ```dockerfile # .clusterfuzzlite/Dockerfile FROM gcr.io/oss-fuzz-base/base-builder-python COPY . $SRC/myproject WORKDIR $SRC/myproject COPY .clusterfuzzlite/build.sh $SRC/ ``` -------------------------------- ### Define Build Environment in Dockerfile Source: https://context7.com/google/clusterfuzzlite/llms.txt Create a Dockerfile for the build environment, installing necessary dependencies and copying project source code. This differs from OSS-Fuzz proper by copying source directly. ```dockerfile # .clusterfuzzlite/Dockerfile FROM gcr.io/oss-fuzz-base/base-builder:v1 # Install project build dependencies RUN apt-get update && apt-get install -y libssl-dev cmake # Copy source code directly into the container COPY . $SRC/myproject # Set working directory and copy build script WORKDIR $SRC/myproject COPY ./.clusterfuzzlite/build.sh $SRC/ ``` -------------------------------- ### Dockerfile Base Image Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/rust_lang.md Start your Dockerfile with the base builder image for Rust projects, which includes Rust and cargo-fuzz. ```dockerfile FROM gcr.io/oss-fuzz-base/base-builder-rust ``` -------------------------------- ### Configure Dockerfile for Python fuzzing Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/python_lang.md Start your Dockerfile with 'gcr.io/oss-fuzz-base/base-builder-python' for Python fuzzing projects. Minimal changes are usually needed as dependencies are pre-installed. ```dockerfile FROM gcr.io/oss-fuzz-base/base-builder-python ``` -------------------------------- ### Java Fuzzer Example with Jazzer (FuzzedDataProvider) Source: https://context7.com/google/clusterfuzzlite/llms.txt Example Java fuzzer using `FuzzedDataProvider` for structured input. It consumes integers and remaining string data to process. ```java // ExampleFuzzerWithProvider.java — structured input via FuzzedDataProvider import com.code_intelligence.jazzer.api.FuzzedDataProvider; public class ExampleFuzzerWithProvider { public static void fuzzerTestOneInput(FuzzedDataProvider data) { int count = data.consumeInt(0, 100); String payload = data.consumeRemainingAsString(); MyClass.processStructured(count, payload); } } ``` -------------------------------- ### Build Fuzz Targets: Basic Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/rust_lang.md Build fuzz targets in release mode using `cargo fuzz build -O`. This example copies a single fuzz target binary to the output directory. ```bash cd $SRC/json cargo fuzz build -O cp fuzz/target/x86_64-unknown-linux-gnu/release/from_slice $OUT/ ``` -------------------------------- ### Python Fuzzer Example with Atheris Source: https://context7.com/google/clusterfuzzlite/llms.txt Example Atheris fuzzer script. It uses `instrument_imports` and `FuzzedDataProvider` to fuzz a module's parse function. ```python # my_fuzzer.py import atheris import sys with atheris.instrument_imports(): import mymodule def TestOneInput(data): fdp = atheris.FuzzedDataProvider(data) value = fdp.ConsumeUnicodeNoSurrogates(32) mymodule.parse(value) atheris.Setup(sys.argv, TestOneInput) atheris.Fuzz() ``` -------------------------------- ### Rust Fuzz Target Example Source: https://context7.com/google/clusterfuzzlite/llms.txt Example of a Rust fuzz target using `libfuzzer_sys`. It parses UTF-8 data and calls a project-specific parse function. ```rust # Fuzz target in fuzz/fuzz_targets/fuzz_parse.rs #![no_main] use libfuzzer_sys::fuzz_target; fuzz_target!(|data: &[u8]| { if let Ok(s) = std::str::from_utf8(data) { let _ = myproject::parse(s); } }); ``` -------------------------------- ### Java Fuzzer Example with Jazzer (Raw Bytes) Source: https://context7.com/google/clusterfuzzlite/llms.txt Example Java fuzzer implementing `fuzzerTestOneInput` for raw byte input, processing it with a `MyClass` method. ```java // ExampleFuzzer.java — raw bytes input public class ExampleFuzzer { public static void fuzzerTestOneInput(byte[] input) { MyClass.processInput(input); } } ``` -------------------------------- ### Dockerfile for ClusterFuzzLite Build Environment Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build_integration.md Defines the Docker image used for building your project. Install necessary packages, copy your source code, and set the working directory for build.sh. ```docker FROM gcr.io/oss-fuzz-base/base-builder:v1 # Base image with clang toolchain RUN apt-get update && apt-get install -y ... # Install required packages to build your project. COPY . $SRC/ # Copy your project's source code. WORKDIR $SRC/ # Working directory for build.sh. COPY ./.clusterfuzzlite/build.sh $SRC/ # Copy build.sh into $SRC dir. ``` -------------------------------- ### Rust Dockerfile for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Dockerfile setup for Rust projects using ClusterFuzzLite. It copies the project source and build script. ```dockerfile # .clusterfuzzlite/Dockerfile FROM gcr.io/oss-fuzz-base/base-builder-rust COPY . $SRC/myproject WORKDIR $SRC/myproject COPY .clusterfuzzlite/build.sh $SRC/ ``` -------------------------------- ### Example JVM Fuzzer Structure Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/jvm_lang.md A basic fuzzer target for JVM projects. It should be a public class with a static method `fuzzerTestOneInput` that accepts a byte array. ```java public class ExampleFuzzer { public static void fuzzerTestOneInput(byte[] input) { ... // Call a function of the project under test with arguments derived from // input and throw an exception if something unwanted happens. ... } } ``` -------------------------------- ### Presubmit Fuzzing Configuration for Prow Source: https://context7.com/google/clusterfuzzlite/llms.txt Configure Prow jobs for presubmit fuzzing with ClusterFuzzLite. This setup provides fast, per-pull request feedback. ```yaml - name: my-project-clusterfuzzlite labels: preset-dind-enabled: "true" decorate: true spec: serviceAccountName: cfl-k8s-sa containers: - image: gcr.io/k8s-testimages/clusterfuzzlite:latest command: [runner.sh] args: [python3, "/opt/oss-fuzz/infra/cifuzz/cifuzz_combined_entrypoint.py"] securityContext: privileged: true env: - name: MODE value: code-change - name: SANITIZER value: address - name: CLOUD_BUCKET value: gs://my-project-fuzzing-bucket - name: CFL_PLATFORM value: prow - name: LANGUAGE value: c++ - name: FUZZ_SECONDS value: "600" ``` -------------------------------- ### Batch Fuzzing Configuration for Prow Source: https://context7.com/google/clusterfuzzlite/llms.txt Configure Prow jobs for nightly batch fuzzing with ClusterFuzzLite. This setup is designed for continuous corpus growth and surfacing deeper bugs. ```yaml - name: my-project-clusterfuzzlite-batch labels: preset-dind-enabled: "true" decorate: true extra_refs: - org: myorg repo: myrepo base_ref: main interval: 24h spec: serviceAccountName: cfl-k8s-sa containers: - image: gcr.io/k8s-testimages/clusterfuzzlite:latest command: [runner.sh] args: [python3, "/opt/oss-fuzz/infra/cifuzz/cifuzz_combined_entrypoint.py"] securityContext: privileged: true env: - name: MODE value: batch - name: SANITIZER value: address - name: CLOUD_BUCKET value: gs://my-project-fuzzing-bucket - name: FUZZ_SECONDS value: "3600" - name: CFL_PLATFORM value: prow - name: LANGUAGE value: c++ ``` -------------------------------- ### Google Cloud Build: Scheduled Batch Fuzzing Source: https://context7.com/google/clusterfuzzlite/llms.txt Configuration for Google Cloud Build to perform scheduled batch fuzzing. This setup includes build and run steps with specific environment variables for batch mode and fuzzing duration. ```yaml # .clusterfuzzlite/cflite_batch.yml — scheduled batch fuzzing steps: - name: gcr.io/oss-fuzz-base/clusterfuzzlite-build-fuzzers:v1 env: - 'CLOUD_BUCKET=gs://my-project-fuzzing-bucket' - 'REPOSITORY=myproject' - 'SANITIZER=address' - 'LANGUAGE=c++' - 'CFL_PLATFORM=gcb' - name: gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers:v1 env: - 'CLOUD_BUCKET=gs://my-project-fuzzing-bucket' - 'REPOSITORY=myproject' - 'SANITIZER=address' - 'LANGUAGE=c++' - 'CFL_PLATFORM=gcb' - 'MODE=batch' - 'FUZZ_SECONDS=3600' ``` -------------------------------- ### Generate Build Integration Files Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build_integration.md Use the helper script to generate the necessary configuration files for build integration. Ensure you are in the oss-fuzz directory and set the PATH_TO_PROJECT environment variable. ```bash cd /path/to/oss-fuzz export PATH_TO_PROJECT= python infra/helper.py generate --external --language=c++ $PATH_TO_PROJECT ``` -------------------------------- ### Build Docker Image and Fuzz Targets Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build_integration.md Build your Docker image and fuzz targets locally. Ensure you replace `
` with the desired sanitizer. ```bash python infra/helper.py build_image --external $PATH_TO_PROJECT ``` ```bash python infra/helper.py build_fuzzers --external $PATH_TO_PROJECT --sanitizer
``` -------------------------------- ### Project Configuration: language Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/rust_lang.md Specify the project language as 'rust' in the `project.yaml` file. ```yaml language: rust ``` -------------------------------- ### Run Formatting, Linting, and Tests Source: https://github.com/google/clusterfuzzlite/blob/main/docs/developing_clusterfuzzlite.md Execute code formatting, linting, and integration tests using the presubmit script. Use -p for parallel execution and -s to skip irrelevant tests. ```bash python infra/presubmit.py format python infra/presubmit.py lint # Run tests in parallel with -p option. Use -s to skip irrelevant tests. END_TO_END_TESTS=1 INTEGRATION_TESTS=1 python infra/presubmit.py infra-tests -p -s ``` -------------------------------- ### Annotated build.sh for JVM Projects Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/jvm_lang.md A sample build script for Java projects with single-file fuzz targets. It includes building the project JAR, setting up the classpath, and creating execution wrappers for Jazzer. ```sh # Step 1: Build the project # Build the project .jar as usual, e.g. using Maven. mvn package # In this example, the project is built with Maven, which typically includes the # project version into the name of the packaged .jar file. The version can be # obtained as follows: CURRENT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \ -Dexpression=project.version -q -DforceStdout) # Copy the project .jar into $OUT under a fixed name. cp "target/sample-project-$CURRENT_VERSION.jar" $OUT/sample-project.jar # Specify the projects .jar file(s), separated by spaces if there are multiple. PROJECT_JARS="sample-project.jar" # Step 2: Build the fuzzers (should not require any changes) # The classpath at build-time includes the project jars in $OUT as well as the # Jazzer API. BUILD_CLASSPATH=$(echo $PROJECT_JARS | xargs printf -- "$OUT/%s:"):$JAZZER_API_PATH # All .jar and .class files lie in the same directory as the fuzzer at runtime. RUNTIME_CLASSPATH=$(echo $PROJECT_JARS | xargs printf -- "\$this_dir/%s:"):\$this_dir for fuzzer in $(find $SRC -name '*Fuzzer.java'); do fuzzer_basename=$(basename -s .java $fuzzer) javac -cp $BUILD_CLASSPATH $fuzzer cp $SRC/$fuzzer_basename.class $OUT/ # Create an execution wrapper that executes Jazzer with the correct arguments. echo "#!/bin/sh # LLVMFuzzerTestOneInput for fuzzer detection. this_dir=\$(dirname \"$0\") LD_LIBRARY_PATH=\"$JVM_LD_LIBRARY_PATH\":\$this_dir \ \$this_dir/jazzer_driver --agent_path=\\$this_dir/jazzer_agent_deploy.jar \ --cp=$RUNTIME_CLASSPATH \ --target_class=$fuzzer_basename \ --jvm_args=\"-Xmx2048m:-Djava.awt.headless=true\" \ \$@" > $OUT/$fuzzer_basename chmod +x $OUT/$fuzzer_basename done ``` -------------------------------- ### Test Build Integration Locally with helper.py Source: https://context7.com/google/clusterfuzzlite/llms.txt Verify the ClusterFuzzLite build and fuzz targets locally before CI integration. Use the helper.py script to build the Docker image and fuzzers, specifying the sanitizer. ```bash # 1. Build the Docker image and fuzz targets python infra/helper.py build_image --external $PATH_TO_PROJECT python infra/helper.py build_fuzzers --external $PATH_TO_PROJECT --sanitizer address ``` -------------------------------- ### Check Build for Common Issues Source: https://context7.com/google/clusterfuzzlite/llms.txt Use this command to verify build compliance with sanitizers and check for immediate crashes. ```bash python infra/helper.py check_build --external $PATH_TO_PROJECT --sanitizer address ``` -------------------------------- ### Registering a New Filestore Source: https://context7.com/google/clusterfuzzlite/llms.txt Register a new filestore implementation in `filestore_utils.py` to make it available for use with ClusterFuzzLite. ```python # infra/cifuzz/filestore_utils.py — register the new filestore FILESTORE_MAPPING = { 'gsutil': 'filestore.gsutil', 'github': 'filestore.github_actions', 'gitlab': 'filestore.gitlab', 'mybucket': 'filestore.mybucket', # Add your filestore here 'no_filestore': 'filestore.no_filestore', } ``` -------------------------------- ### Java/JVM Build Script for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Placeholder for the Java/JVM build script. This script would typically handle compilation and Jazzer setup. ```sh #!/bin/bash -eu ``` -------------------------------- ### Add Go Project Dependencies in Dockerfile Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/go_lang.md Use 'RUN git clone' commands in your Dockerfile to fetch dependencies for your Go project before go-fuzz automatically downloads them based on go.mod. ```dockerfile # Dependency for one of the fuzz targets. RUN git clone --depth 1 https://github.com/ianlancetaylor/demangle ``` -------------------------------- ### Build Fuzz Targets: All Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/rust_lang.md Automatically copy all fuzz target binaries to the output directory by iterating through fuzz target files. This ensures new targets are automatically integrated. ```bash FUZZ_TARGET_OUTPUT_DIR=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 ``` -------------------------------- ### Writing a Fuzz Target (C/C++) Source: https://context7.com/google/clusterfuzzlite/llms.txt Implement the LLVMFuzzerTestOneInput function to receive fuzzing input. Link against the libFuzzer engine using the $LIB_FUZZING_ENGINE environment variable. ```cpp // fuzz_target.cc #include #include extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { // Pass fuzzer-generated bytes into the function under test. // Sanitizers will detect crashes, memory errors, or undefined behavior. DoSomethingInterestingWithMyAPI(Data, Size); return 0; // Non-zero return values are reserved for future use. } ``` -------------------------------- ### Create Python fuzzers with PyInstaller and wrappers Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/python_lang.md This script iterates through Python fuzzers, uses PyInstaller to create standalone packages, and generates execution wrappers. The wrapper ensures Atheris compatibility by preloading necessary libraries and setting ASAN options. ```shell # Build fuzzers into $OUT. These could be detected in other ways. for fuzzer in $(find $SRC -name '*_fuzzer.py'); do fuzzer_basename=$(basename -s .py $fuzzer) fuzzer_package=${fuzzer_basename}.pkg # To avoid issues with Python version conflicts, or changes in environment # over time, we use pyinstaller to create a standalone # package. Though not necessarily required for reproducing issues, this is # required to keep fuzzers working properly. pyinstaller --distpath $OUT --onefile --name $fuzzer_package $fuzzer # Create execution wrapper. Atheris requires that certain libraries are # preloaded, so this is also done here to ensure compatibility and simplify # test case reproduction. Since this helper script is what will # actually execute, it is also always required. # NOTE: If you are fuzzing python-only code and do not have native C/C++ # extensions, then remove the LD_PRELOAD line below as preloading sanitizer # library is not required and can lead to unexpected startup crashes. echo "#!/bin/sh # LLVMFuzzerTestOneInput for fuzzer detection. this_dir=\$(dirname \"$0\") LD_PRELOAD=$this_dir/sanitizer_with_fuzzer.so \ ASAN_OPTIONS=$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=$this_dir/llvm-symbolizer:detect_leaks=0 \ $this_dir/$fuzzer_package $@" > $OUT/$fuzzer_basename chmod +x $OUT/$fuzzer_basename done ``` -------------------------------- ### Run Fuzzer for Short Trial Source: https://context7.com/google/clusterfuzzlite/llms.txt Execute a specific fuzz target for a limited duration to test its functionality. ```bash python infra/helper.py run_fuzzer \ --external \ --corpus-dir=/tmp/my-corpus \ $PATH_TO_PROJECT \ parse_fuzzer ``` -------------------------------- ### Java Fuzz Target with FuzzedDataProvider Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/jvm_lang.md Example of a Java fuzz target using FuzzedDataProvider to consume primitive types and strings from fuzzer input. Ensure the jazzer-api library is available in the classpath. ```java import com.code_intelligence.jazzer.api.FuzzedDataProvider; public class ExampleFuzzer { public static void fuzzerTestOneInput(FuzzedDataProvider data) { int number = data.consumeInt(); String string = data.consumeRemainingAsString(); // ... } } ``` -------------------------------- ### Coverage Reports Configuration for Google Cloud Build Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/google_cloud_build.md Configure your .clusterfuzzlite/cflite_coverage.yml with this YAML to generate periodic coverage reports using the latest fuzzing corpus. This setup utilizes Google Cloud Build for processing and reporting. ```yaml steps: - name: gcr.io/oss-fuzz-base/clusterfuzzlite-build-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'LANGUAGE=c++' # Change this to your project's language. - 'SANITIZER=coverage' - 'CFL_PLATFORM=gcb' - name: gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'LANGUAGE=c++' # Change this to your project's language. - 'MODE=coverage - 'SANITIZER=coverage' - 'CFL_PLATFORM=gcb' ``` -------------------------------- ### Custom Platform Configuration Source: https://context7.com/google/clusterfuzzlite/llms.txt Implement a custom platform configuration by inheriting from `BasePlatformConfig`. This allows integration with new CI systems. ```python # infra/cifuzz/platform_config/myplatform.py from platform_config import BasePlatformConfig class PlatformConfig(BasePlatformConfig): """PlatformConfig for MyPlatform CI.""" @property def workspace(self): return os.environ.get('MYPLATFORM_WORKSPACE', '/workspace') @property def git_base_commit(self): # Map platform-specific variable name to ClusterFuzzLite's expected name return os.environ.get('MYPLATFORM_BASE_COMMIT') ``` -------------------------------- ### Generate ClusterFuzzLite Build Integration Files Source: https://context7.com/google/clusterfuzzlite/llms.txt Use the OSS-Fuzz helper script to generate stub configuration files for ClusterFuzzLite integration. Ensure the oss-fuzz repository is cloned locally and the project path is set. ```bash # Generate empty build integration files (requires oss-fuzz repo cloned locally) cd /path/to/oss-fuzz export PATH_TO_PROJECT=/path/to/your/project python infra/helper.py generate --external --language=c++ $PATH_TO_PROJECT # Creates: .clusterfuzzlite/project.yaml # .clusterfuzzlite/Dockerfile # .clusterfuzzlite/build.sh ``` -------------------------------- ### Corpus Pruning Configuration for Google Cloud Build Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/google_cloud_build.md Add this YAML configuration to your .clusterfuzzlite/cflite_cron.yml to enable corpus pruning. This setup minimizes your fuzzing corpus by removing redundant test cases while preserving code coverage, using Google Cloud Build. ```yaml jobs: steps: - name: gcr.io/oss-fuzz-base/clusterfuzzlite-build-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'SANITIZER=address' # This can be changed to other sanitizers you use. - 'LANGUAGE=c++' # Change this to your project's language. - 'CFL_PLATFORM=gcb' - name: gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'SANITIZER=address' # This can be changed to other sanitizers you use. - 'LANGUAGE=c++' # Change this to your project's language. - 'CFL_PLATFORM=gcb' - 'MODE=prune' ``` -------------------------------- ### Check for Common Build Issues Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build_integration.md Run this command to check if your fuzz targets are compiled correctly with the specified sanitizer and do not crash after a short fuzzing period. Replace `
` with the desired sanitizer. ```bash python infra/helper.py check_build --external $PATH_TO_PROJECT --sanitizer
``` -------------------------------- ### GitLab CI Job for Batch Fuzzing and Corpus Pruning Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/gitlab.md Configure this job in `.gitlab-ci.yml` for scheduled batch fuzzing and corpus pruning. Set the `MODE` variable to `batch` or `prune` via GitLab CI schedules. This job uses the same image and setup as the MR fuzzing job. ```yaml clusterfuzzlite-corpus: image: name: gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers:v1 entrypoint: [""] services: - docker:dind # may be removed in self-managed GitLab instances stage: test rules: - if: $MODE == "prune" - if: $MODE == "batch" before_script: - export CFL_CONTAINER_ID=`docker ps -q -f "label=com.gitlab.gitlab-runner.job.id=$CI_JOB_ID" -f "label=com.gitlab.gitlab-runner.type=build"` script: - python3 "/opt/oss-fuzz/infra/cifuzz/cifuzz_combined_entrypoint.py" artifacts: when: always paths: - artifacts/ ``` -------------------------------- ### Create Google Cloud Service Account Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/prow.md Use this command to create a new Google Cloud service account for ClusterFuzzLite. ```bash gcloud beta iam service-accounts create `` --project=`` --description=`` --display-name=`` ``` -------------------------------- ### Configure GitHub Actions for Coverage Reports Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/github_actions.md Integrate this job into your .github/workflows/cflite_cron.yml to generate periodic coverage reports. Ensure the 'language' and 'sanitizer' fields are set correctly for your project. ```yaml jobs: Coverage: runs-on: ubuntu-latest steps: - name: Build Fuzzers id: build uses: google/clusterfuzzlite/actions/build_fuzzers@v1 with: language: c++ # Change this to the language you are fuzzing. sanitizer: coverage - name: Run Fuzzers id: run uses: google/clusterfuzzlite/actions/run_fuzzers@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} fuzz-seconds: 600 mode: 'coverage' sanitizer: 'coverage' # Optional but recommended. # See later section on "Git repo for storage". # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git # storage-repo-branch: main # Optional. Defaults to "main" # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". ``` -------------------------------- ### Go Project Configuration for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Project configuration file for Go projects in ClusterFuzzLite. Note that only the 'address' sanitizer is supported. ```yaml # .clusterfuzzlite/project.yaml language: go # Note: only 'address' sanitizer is supported for Go ``` -------------------------------- ### Build Go Fuzz Target with compile_go_fuzzer Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/go_lang.md Use the 'compile_go_fuzzer' script in build.sh to build Go fuzz targets. This script handles linking against the libFuzzer engine and supports coverage builds. ```sh compile_go_fuzzer github.com/miekg/dns FuzzNewRR fuzz_newrr fuzz ``` -------------------------------- ### Specify Go Language in project.yaml Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/go_lang.md Set the 'language' attribute to 'go' in your project.yaml file to indicate a Go project. ```yaml language: go ``` -------------------------------- ### Build Swift Project with SWIFTFLAGS Source: https://github.com/google/clusterfuzzlite/blob/main/docs/build-integration/swift.md Use the 'precompile_swift' script to generate the SWIFTFLAGS environment variable, which can then be included in your 'swift build' command for release or debug builds. ```sh . precompile_swift # build project cd FuzzTesting swift build -c debug $SWIFTFLAGS ( cd .build/debug/ find . -maxdepth 1 -type f -name "*Fuzzer" -executable | while read i; do cp $i $OUT/"$i"-debug; done ) ``` -------------------------------- ### Configure PR Fuzzing Workflow Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/github_actions.md Add this default configuration to `.github/workflows/cflite_pr.yml` to fuzz all pull requests to your repository. Customize language, sanitizers, and fuzzing duration as needed. ```yaml name: ClusterFuzzLite PR fuzzing on: pull_request: paths: - '**' 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 # Override this with the sanitizers you want. # - undefined # - memory steps: - name: Build Fuzzers (${{ matrix.sanitizer }}) id: build uses: google/clusterfuzzlite/actions/build_fuzzers@v1 with: language: c++ # Change this to the language you are fuzzing. github-token: ${{ secrets.GITHUB_TOKEN }} sanitizer: ${{ matrix.sanitizer }} # Optional but recommended: used to only run fuzzers that are affected # by the PR. # See later section on "Git repo for storage". # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git # storage-repo-branch: main # Optional. Defaults to "main" # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". - name: Run Fuzzers (${{ matrix.sanitizer }}) id: run uses: google/clusterfuzzlite/actions/run_fuzzers@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} fuzz-seconds: 600 mode: 'code-change' sanitizer: ${{ matrix.sanitizer }} output-sarif: true # Optional but recommended: used to download the corpus produced by # batch fuzzing. # See later section on "Git repo for storage". # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git # storage-repo-branch: main # Optional. Defaults to "main" # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". ``` -------------------------------- ### Prow Job Config for Batch Fuzzing Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/prow.md Configure your Prow job to enable batch fuzzing by setting the MODE environment variable to 'batch'. Ensure all placeholder values like , , , , , and are replaced with your specific details. Adjust FUZZ_SECONDS and SANITIZER as needed. ```yaml - name: labels: preset-dind-enabled: "true" decorate: true extra_refs: - org: repo: base_ref: # This should be the branch you want to fuzz. interval: 24h # This can be a cron as well. spec: serviceAccountName: containers: - image: gcr.io/k8s-testimages/clusterfuzzlite:latest command: - runner.sh args: - python3 - "/opt/oss-fuzz/infra/cifuzz/cifuzz_combined_entrypoint.py" # docker-in-docker needs privileged mode securityContext: privileged: true env: - name: MODE value: batch - name: SANITIZER value: address # Change this to whatever sanitizer you want to use. - name: CLOUD_BUCKET value: - name: FUZZ_SECONDS value: 3600 # 1 Hour. You can change this. - name: CFL_PLATFORM value: prow - name: LANGUAGE value: go # Change this to whatever language you are fuzzing ``` -------------------------------- ### Configure GitLab Pages Job for Coverage Reports Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/gitlab.md Set up a `pages` job in your coverage repository's `.gitlab-ci.yml` to serve coverage reports using GitLab Pages. This job copies all content to a `public` directory, which GitLab Pages then hosts. ```yaml pages: script: - mkdir .public - cp -r * .public - mv .public public artifacts: paths: - public ``` -------------------------------- ### Configure Batch Fuzzing in GitHub Actions Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/github_actions.md Use this YAML configuration to set up scheduled batch fuzzing. Customize the cron schedule, language, and sanitizers as needed. The 'run_fuzzers' action handles the fuzzing execution. ```yaml name: ClusterFuzzLite batch fuzzing on: schedule: - cron: '0 0/6 * * *' # Every 6th hour. Change this to whatever is suitable. permissions: read-all jobs: BatchFuzzing: runs-on: ubuntu-latest strategy: fail-fast: false matrix: sanitizer: - address # Override this with the sanitizers you want. # - undefined # - memory steps: - name: Build Fuzzers (${{ matrix.sanitizer }}) id: build uses: google/clusterfuzzlite/actions/build_fuzzers@v1 with: language: c++ # Change this to the language you are fuzzing. sanitizer: ${{ matrix.sanitizer }} - name: Run Fuzzers (${{ matrix.sanitizer }}) id: run uses: google/clusterfuzzlite/actions/run_fuzzers@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} fuzz-seconds: 3600 mode: 'batch' sanitizer: ${{ matrix.sanitizer }} output-sarif: true # Optional but recommended: For storing certain artifacts from fuzzing. # See later section on "Git repo for storage". # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git # storage-repo-branch: main # Optional. Defaults to "main" # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". ``` -------------------------------- ### Custom Filestore Implementation Source: https://context7.com/google/clusterfuzzlite/llms.txt Implement a custom filestore by inheriting from `BaseFilestore`. This enables ClusterFuzzLite to use custom storage backends for artifacts and corpora. ```python # infra/cifuzz/filestore/mybucket/__init__.py from filestore import BaseFilestore class MyBucketFilestore(BaseFilestore): """Filestore implementation backed by MyBucket storage.""" def upload_directory(self, upload_url, local_path): # Implement uploading local_path to upload_url in your storage system ... def download_directory(self, download_url, local_path): # Implement downloading from download_url to local_path ... ``` -------------------------------- ### Generate Coverage Report Source: https://context7.com/google/clusterfuzzlite/llms.txt Build fuzzers with coverage instrumentation and then generate a coverage report from the collected corpus. ```bash python infra/helper.py build_fuzzers --external --sanitizer coverage $PATH_TO_PROJECT python infra/helper.py coverage \ --external \ $PATH_TO_PROJECT \ --fuzz-target=parse_fuzzer \ --corpus-dir=/tmp/my-corpus ``` -------------------------------- ### Batch Fuzzing Configuration for Google Cloud Build Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/google_cloud_build.md Use this YAML configuration in your .clusterfuzzlite/cflite_batch.yml file to enable batch fuzzing. It defines steps for building fuzzers and running them in batch mode on Google Cloud Build. Customize CLOUD_BUCKET, REPOSITORY, SANITIZER, LANGUAGE, and FUZZ_SECONDS as needed. ```yaml steps: - name: gcr.io/oss-fuzz-base/clusterfuzzlite-build-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'SANITIZER=address' # This can be changed to other sanitizers you use. - 'LANGUAGE=c++' # Change this to your project's language. - 'CFL_PLATFORM=gcb' - name: gcr.io/oss-fuzz-base/clusterfuzzlite-run-fuzzers:v1 env: - 'CLOUD_BUCKET=' - 'REPOSITORY=' - 'SANITIZER=address' # This can be changed to other sanitizers you use. - 'LANGUAGE=c++' # Change this to your project's language. - 'CFL_PLATFORM=gcb' - 'MODE=batch - 'FUZZ_SECONDS=3600' # You can change this to a value you prefer. ``` -------------------------------- ### Fuzzer Build Script with libFuzzer Linking Source: https://context7.com/google/clusterfuzzlite/llms.txt Write a build.sh script to compile the project using ClusterFuzzLite's environment variables. Link fuzz targets against libFuzzer using $CXX and $LIB_FUZZING_ENGINE, placing binaries in $OUT. ```bash #!/bin/bash -eu # .clusterfuzzlite/build.sh # Build the project using ClusterFuzzLite's compilers and flags ./configure --disable-shared make -j$(nproc) all # Link a fuzz target against libFuzzer using $LIB_FUZZING_ENGINE # Use $CXX for linking even in C projects $CXX $CXXFLAGS -std=c++11 \ -I./include \ $SRC/parse_fuzzer.cc \ -o $OUT/parse_fuzzer \ $LIB_FUZZING_ENGINE ./lib/libmyproject.a # Optionally copy seed corpus and dictionary files cp $SRC/*.dict $OUT/ 2>/dev/null || true cp $SRC/*.options $OUT/ 2>/dev/null || true ``` -------------------------------- ### Configure Continuous Builds in GitHub Actions Source: https://github.com/google/clusterfuzzlite/blob/main/docs/running-clusterfuzzlite/github_actions.md Set up continuous builds to trigger a build and upload artifacts on every push to the main branch. This is useful for determining if a crash found during PR fuzzing is newly introduced. Ensure 'upload-build' is set to true. ```yaml name: ClusterFuzzLite continuous builds on: push: branches: - main # Use your actual default branch here. permissions: read-all jobs: Build: runs-on: ubuntu-latest concurrency: group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }} cancel-in-progress: true strategy: fail-fast: false matrix: sanitizer: - address # Override this with the sanitizers you want. # - undefined # - memory steps: - name: Build Fuzzers (${{ matrix.sanitizer }}) id: build uses: google/clusterfuzzlite/actions/build_fuzzers@v1 with: language: c++ # Change this to the language you are fuzzing. sanitizer: ${{ matrix.sanitizer }} upload-build: true ``` -------------------------------- ### GitHub Actions: Batch Fuzzing with ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Sets up scheduled batch fuzzing jobs using GitHub Actions. This mode runs fuzzers for extended periods to build corpus and find deeper bugs, without exiting on the first crash. ```yaml # .github/workflows/cflite_batch.yml name: ClusterFuzzLite batch fuzzing on: schedule: - cron: '0 0/6 * * *' # Every 6 hours; adjust as needed permissions: read-all jobs: BatchFuzzing: runs-on: ubuntu-latest strategy: fail-fast: false matrix: sanitizer: [address] steps: - name: Build Fuzzers (${{ matrix.sanitizer }}) uses: google/clusterfuzzlite/actions/build_fuzzers@v1 with: language: c++ sanitizer: ${{ matrix.sanitizer }} - name: Run Fuzzers (${{ matrix.sanitizer }}) uses: google/clusterfuzzlite/actions/run_fuzzers@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} fuzz-seconds: 3600 # 1 hour for batch fuzzing mode: 'batch' sanitizer: ${{ matrix.sanitizer }} output-sarif: true storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO.git storage-repo-branch: main storage-repo-branch-coverage: gh-pages ``` -------------------------------- ### Build ClusterFuzzLite Docker Images Source: https://github.com/google/clusterfuzzlite/blob/main/docs/developing_clusterfuzzlite.md Rebuild the ClusterFuzzLite Docker images locally to include your source code changes for end-to-end testing. ```bash ./infra/cifuzz/build-images.sh ``` -------------------------------- ### Go Build Script for ClusterFuzzLite Source: https://context7.com/google/clusterfuzzlite/llms.txt Build script for Go fuzz targets using `compile_go_fuzzer`. Specify package path, fuzz function name, and output binary name. ```sh # .clusterfuzzlite/build.sh compile_go_fuzzer github.com/miekg/dns FuzzNewRR fuzz_newrr fuzz # Args: [build-tag] ```