-
Notifications
You must be signed in to change notification settings - Fork 524
Add fuzzer harnesses #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add fuzzer harnesses #433
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Fuzzer harnesses for H3 | ||
|
||
This directory contains helper programs for testing the H3 library using the | ||
''[American fuzzy lop](https://lcamtuf.coredump.cx/afl/)'' fuzzer. | ||
|
||
# Installation | ||
|
||
``` | ||
apt install afl-clang | ||
``` | ||
|
||
(There is also an afl-cov which looks interesting but isn't necessary.) | ||
|
||
# Usage | ||
|
||
You must compile with the instrumented compiler: | ||
|
||
``` | ||
CXX=afl-clang++ CC=afl-clang cmake . | ||
make fuzzers | ||
``` | ||
|
||
An individual fuzzer run is invoked as follows. The argument is a file containing the number of bytes needed. | ||
|
||
``` | ||
fuzzerGeoToH3 bytes24 | ||
``` | ||
|
||
To begin running the fuzzer, run the following. The testcase directory (`testcase_dir`) should contain a file | ||
with at least the right number of bytes that the fuzzer will read (such as 16 for fuzzerKRing.) | ||
|
||
``` | ||
afl-fuzz -i testcase_dir -o findings_dir -- fuzzerGeoToH3 @@ | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2021 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** @file | ||
* @brief Fuzzer program for geoToH3 | ||
*/ | ||
|
||
#include "h3api.h" | ||
#include "utility.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc != 2) { | ||
error("Should have one argument (test case file)\n"); | ||
} | ||
const char* filename = argv[1]; | ||
FILE* fp = fopen(filename, "rb"); | ||
struct args { | ||
double lat; | ||
double lon; | ||
int res; | ||
} args; | ||
if (fread(&args, sizeof(args), 1, fp) != 1) { | ||
error("Error reading\n"); | ||
} | ||
fclose(fp); | ||
|
||
GeoCoord g = {.lat = args.lat, .lon = args.lon}; | ||
H3Index h = H3_EXPORT(geoToH3)(&g, args.res); | ||
|
||
h3Println(h); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2021 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** @file | ||
* @brief Fuzzer program for h3ToGeo and h3ToGeoBoundary | ||
*/ | ||
|
||
#include "h3api.h" | ||
#include "utility.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc != 2) { | ||
error("Should have one argument (test case file)\n"); | ||
} | ||
const char* filename = argv[1]; | ||
FILE* fp = fopen(filename, "rb"); | ||
H3Index index; | ||
if (fread(&index, sizeof(H3Index), 1, fp) != 1) { | ||
error("Error reading\n"); | ||
} | ||
fclose(fp); | ||
|
||
GeoCoord geo; | ||
H3_EXPORT(h3ToGeo)(index, &geo); | ||
printf("%lf %lf\n", geo.lat, geo.lon); | ||
GeoBoundary geoBoundary; | ||
H3_EXPORT(h3ToGeoBoundary)(index, &geoBoundary); | ||
printf("%d\n", geoBoundary.numVerts); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** @file | ||
* @brief Fuzzer program for kRing | ||
*/ | ||
|
||
#include "h3api.h" | ||
#include "utility.h" | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc != 2) { | ||
error("Should have one argument (test case file)\n"); | ||
} | ||
const char* filename = argv[1]; | ||
FILE* fp = fopen(filename, "rb"); | ||
struct { | ||
H3Index index; | ||
int k; | ||
} args; | ||
if (fread(&args, sizeof(args), 1, fp) != 1) { | ||
error("Error reading\n"); | ||
} | ||
fclose(fp); | ||
|
||
int sz = H3_EXPORT(maxKringSize)(args.k); | ||
H3Index* results = calloc(sizeof(H3Index), sz); | ||
if (results != NULL) { | ||
H3_EXPORT(kRing)(args.index, args.k, results); | ||
h3Println(results[0]); | ||
} | ||
free(results); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the file arguments here. Are these files we could check into the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't they invoked by the new fuzzer test commands with random data over and over again in the attempt to cause breakage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is an example of how to test the fuzzer program (check that it does what you think it does) before putting it through AFL. I didn't check in the initial files (like
bytes24
) because they had no useful content - they were just ASCII'0'
repeated a given number of times and then I had the fuzzer permute from that. I could add either a script that sets up the file or check in a binary file of the right size to make it easier to start the fuzzer.