Skip to content

Commit 00bc707

Browse files
authored
Merge pull request #1903 from DaveLak/fuzzing-integration-follow-ups
Fuzzer Migration Follow-ups
2 parents e3fb1f2 + 1d54d4b commit 00bc707

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

Diff for: fuzzing/README.md

+16-18
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This directory contains files related to GitPython's suite of fuzz tests that ar
66
infrastructure provided by [OSS-Fuzz][oss-fuzz-repo]. This document aims to provide necessary information for working
77
with fuzzing in GitPython.
88

9-
The latest details regarding OSS-Fuzz test status, including build logs and coverage reports, is made available
10-
at [this link](https://introspector.oss-fuzz.com/project-profile?project=gitpython).
9+
The latest details regarding OSS-Fuzz test status, including build logs and coverage reports, is available
10+
on [the Open Source Fuzzing Introspection website](https://introspector.oss-fuzz.com/project-profile?project=gitpython).
1111

1212
## How to Contribute
1313

@@ -129,47 +129,45 @@ This approach uses Docker images provided by OSS-Fuzz for building and running f
129129
comprehensive features but requires a local clone of the OSS-Fuzz repository and sufficient disk space for Docker
130130
containers.
131131

132-
#### Preparation
133-
134-
Set environment variables to simplify command usage:
135-
136-
```shell
137-
# $SANITIZER can be either 'address' or 'undefined':
138-
export SANITIZER=address
139-
# specify the fuzz target without the .py extension:
140-
export FUZZ_TARGET=fuzz_config
141-
```
142-
143-
#### Build and Run
132+
#### Build the Execution Environment
144133

145134
Clone the OSS-Fuzz repository and prepare the Docker environment:
146135

147136
```shell
148137
git clone --depth 1 https://github.com/google/oss-fuzz.git oss-fuzz
149138
cd oss-fuzz
150139
python infra/helper.py build_image gitpython
151-
python infra/helper.py build_fuzzers --sanitizer $SANITIZER gitpython
140+
python infra/helper.py build_fuzzers --sanitizer address gitpython
152141
```
153142

154143
> [!TIP]
155-
> The `build_fuzzers` command above accepts a local file path pointing to your gitpython repository clone as the last
144+
> The `build_fuzzers` command above accepts a local file path pointing to your GitPython repository clone as the last
156145
> argument.
157146
> This makes it easy to build fuzz targets you are developing locally in this repository without changing anything in
158147
> the OSS-Fuzz repo!
159148
> For example, if you have cloned this repository (or a fork of it) into: `~/code/GitPython`
160149
> Then running this command would build new or modified fuzz targets using the `~/code/GitPython/fuzzing/fuzz-targets`
161150
> directory:
162151
> ```shell
163-
> python infra/helper.py build_fuzzers --sanitizer $SANITIZER gitpython ~/code/GitPython
152+
> python infra/helper.py build_fuzzers --sanitizer address gitpython ~/code/GitPython
164153
> ```
165154
166-
167155
Verify the build of your fuzzers with the optional `check_build` command:
168156
169157
```shell
170158
python infra/helper.py check_build gitpython
171159
```
172160
161+
#### Run a Fuzz Target
162+
163+
Setting an environment variable for the fuzz target argument of the execution command makes it easier to quickly select
164+
a different target between runs:
165+
166+
```shell
167+
# specify the fuzz target without the .py extension:
168+
export FUZZ_TARGET=fuzz_config
169+
```
170+
173171
Execute the desired fuzz target:
174172

175173
```shell

Diff for: fuzzing/fuzz-targets/fuzz_config.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/python3
21
# Copyright 2023 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

Diff for: fuzzing/fuzz-targets/fuzz_tree.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/python3
21
# Copyright 2023 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");

Diff for: fuzzing/oss-fuzz-scripts/build.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env bash
1+
# shellcheck shell=bash
22

33
set -euo pipefail
44

55
python3 -m pip install .
66

7-
# Directory to look in for dictionaries, options files, and seed corpa:
7+
# Directory to look in for dictionaries, options files, and seed corpora:
88
SEED_DATA_DIR="$SRC/seed_data"
99

1010
find "$SEED_DATA_DIR" \( -name '*_seed_corpus.zip' -o -name '*.options' -o -name '*.dict' \) \
@@ -13,7 +13,7 @@ find "$SEED_DATA_DIR" \( -name '*_seed_corpus.zip' -o -name '*.options' -o -name
1313
-exec cp {} "$OUT" \;
1414

1515
# Build fuzzers in $OUT.
16-
find "$SRC/gitpython/fuzzing" -name 'fuzz_*.py' -print0 | while IFS= read -r -d $'\0' fuzz_harness; do
16+
find "$SRC/gitpython/fuzzing" -name 'fuzz_*.py' -print0 | while IFS= read -r -d '' fuzz_harness; do
1717
compile_python_fuzzer "$fuzz_harness"
1818

1919
common_base_dictionary_filename="$SEED_DATA_DIR/__base.dict"
@@ -27,7 +27,7 @@ find "$SRC/gitpython/fuzzing" -name 'fuzz_*.py' -print0 | while IFS= read -r -d
2727
# If a dictionary file for this fuzzer already exists and is not empty,
2828
# we append a new line to the end of it before appending any new entries.
2929
#
30-
# libfuzzer will happily ignore multiple empty lines in a dictionary but crash
30+
# LibFuzzer will happily ignore multiple empty lines in a dictionary but fail with an error
3131
# if any single line has incorrect syntax (e.g., if we accidentally add two entries to the same line.)
3232
# See docs for valid syntax: https://llvm.org/docs/LibFuzzer.html#id32
3333
echo >>"$output_file"

Diff for: fuzzing/oss-fuzz-scripts/container-environment-bootstrap.sh

100644100755
+7-6
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ download_and_concatenate_common_dictionaries() {
3434
done
3535
}
3636

37-
fetch_seed_corpra() {
37+
fetch_seed_corpora() {
3838
# Seed corpus zip files are hosted in a separate repository to avoid additional bloat in this repo.
3939
git clone --depth 1 https://github.com/gitpython-developers/qa-assets.git qa-assets &&
4040
rsync -avc qa-assets/gitpython/corpra/ "$SEED_DATA_DIR/" &&
41-
rm -rf qa-assets; # Clean up the cloned repo to keep the Docker image as slim as possible.
41+
rm -rf qa-assets # Clean up the cloned repo to keep the Docker image as slim as possible.
4242
}
4343

4444
########################
4545
# Main execution logic #
4646
########################
4747

48-
fetch_seed_corpra;
48+
fetch_seed_corpora
4949

5050
download_and_concatenate_common_dictionaries "$SEED_DATA_DIR/__base.dict" \
5151
"https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/utf8.dict" \
52-
"https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/url.dict";
52+
"https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/url.dict"
5353

5454
# The OSS-Fuzz base image has outdated dependencies by default so we upgrade them below.
55-
python3 -m pip install --upgrade pip;
56-
python3 -m pip install 'setuptools~=69.0' 'pyinstaller~=6.0'; # Uses the latest versions know to work at the time of this commit.
55+
python3 -m pip install --upgrade pip
56+
# Upgrade to the latest versions known to work at the time the below changes were introduced:
57+
python3 -m pip install 'setuptools~=69.0' 'pyinstaller~=6.0'

0 commit comments

Comments
 (0)