This directory contains files related to GitPython's suite of fuzz tests that are executed daily on automated infrastructure provided by OSS-Fuzz. This document aims to provide necessary information for working with fuzzing in GitPython.
The latest details regarding OSS-Fuzz test status, including build logs and coverage reports, is available on the Open Source Fuzzing Introspection website.
There are many ways to contribute to GitPython's fuzzing efforts! Contributions are welcomed through issues, discussions, or pull requests on this repository.
Areas that are particularly appreciated include:
For everything else, such as expanding test coverage, optimizing test performance, or enhancing error detection capabilities, jump into the "Getting Started" section below.
Tip
New to fuzzing or unfamiliar with OSS-Fuzz?
These resources are an excellent place to start:
Before contributing to fuzzing efforts, ensure Python and Docker are installed on your machine. Docker is required for running fuzzers in containers provided by OSS-Fuzz and for safely executing test files directly. Install Docker following the official guide if you do not already have it.
Review the fuzz-targets/ directory to familiarize yourself with how existing tests are implemented. See the Files & Directories Overview for more details on the directory structure.
Start by reviewing the Atheris documentation and the section on Running Fuzzers Locally to begin writing or improving fuzz tests.
The fuzzing/ directory is organized into three key areas:
Contains Python files for each fuzz test.
Things to Know:
Includes scripts for building and integrating fuzz targets with OSS-Fuzz:
Where to learn more:
Contains tools to make local development tasks easier. See the "Running Fuzzers Locally" section below for further documentation and use cases related to files found here.
Warning
Some fuzz targets in this repository write to the filesystem during execution. For that reason, it is strongly recommended to always use Docker when executing fuzz targets, even when it may be possible to do so without it.
Although I/O operations such as writing to disk are not considered best practice, the current implementation of at least one test requires it. See the "Setting Up Your Local Environment" section above if you do not already have Docker installed on your machine.
PRs that replace disk I/O with in-memory alternatives are very much welcomed!
Directly executing fuzz targets allows for quick iteration and testing of changes which can be helpful during early development of new fuzz targets or for validating changes made to an existing test. The Dockerfile located in the local-dev-helpers/ subdirectory provides a lightweight container environment preconfigured with Atheris that makes it easy to execute a fuzz target directly.
From the root directory of your GitPython repository clone:
The above command executes fuzz_config.py and exits after 10000 runs, or earlier if the fuzzer finds an error.
Docker CLI's -v flag specifies a volume mount in Docker that maps the directory in which the command is run (which should be the root directory of your local GitPython clone) to a directory inside the container, so any modifications made between invocations will be reflected immediately without the need to rebuild the image each time.
This approach uses Docker images provided by OSS-Fuzz for building and running fuzz tests locally. It offers comprehensive features but requires a local clone of the OSS-Fuzz repository and sufficient disk space for Docker containers.
Clone the OSS-Fuzz repository and prepare the Docker environment:
Tip
The build_fuzzers command above accepts a local file path pointing to your GitPython repository clone as the last argument. This makes it easy to build fuzz targets you are developing locally in this repository without changing anything in the OSS-Fuzz repo! For example, if you have cloned this repository (or a fork of it) into: ~/code/GitPython Then running this command would build new or modified fuzz targets using the ~/code/GitPython/fuzzing/fuzz-targets directory:
Verify the build of your fuzzers with the optional check_build command:
Setting an environment variable for the fuzz target argument of the execution command makes it easier to quickly select a different target between runs:
Execute the desired fuzz target:
Tip
In the example above, the "-- -max_total_time=60 -print_final_stats=1" portion of the command is optional but quite useful.
Every argument provided after "--" in the above command is passed to the fuzzing engine directly. In this case:
But almost any LibFuzzer option listed in the documentation should work as well.
For detailed instructions on advanced features like reproducing OSS-Fuzz issues or using the Fuzz Introspector, refer to the official OSS-Fuzz documentation.
All files located within the fuzzing/ directory are subject to the same license as the other files in this repository with one exception:
fuzz_config.py was migrated to this repository from the OSS-Fuzz project's repository where it was originally created. As such, fuzz_config.py retains its original license and copyright notice (Apache License, Version 2.0 and Copyright 2023 Google LLC respectively) as in a header comment, followed by a notice stating that it has have been modified contributors to GitPython. LICENSE-APACHE contains the original license used by the OSS-Fuzz project repository at the time the file was migrated.