Skip to content
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

Add polygonToCellsNoHoles fuzzer #557

Merged
merged 36 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0277ce5
Add LLVM fuzzer harness
Dec 22, 2021
1c8ec2e
Add AFL++ test case generator
Dec 22, 2021
b89c76b
Fuzz more gridDisk functions
Dec 22, 2021
79d2e2c
add fuzzerH3SetToLinkedGeo
Dec 22, 2021
a28a807
Add more fuzzers
Dec 22, 2021
9445cbb
Additional fuzzers
Dec 22, 2021
f971dcf
add fuzzerVertexes
Dec 22, 2021
e0c8841
Add test-fuzzer script
Dec 22, 2021
007b7c3
Fix linux build
Dec 22, 2021
02abb99
Fix fuzzerIndexIO
Dec 22, 2021
caedc90
test-fuzzer use subshell for ls
isaacbrodsky Dec 22, 2021
de5a2c3
Update test-fuzzer again
isaacbrodsky Dec 22, 2021
8bbc36a
Fix test-fuzzer again
isaacbrodsky Dec 22, 2021
021c994
fuzzerCompact
Dec 23, 2021
2195863
Update readme
Dec 23, 2021
4a65123
libFuzzer tests
Dec 23, 2021
1e7066e
reformat header
Dec 23, 2021
0ede718
README updates
Dec 23, 2021
65b4ef3
fuzzerDirectedEdge
Dec 23, 2021
79b1f44
fuzzerLocalIj
Dec 23, 2021
25360ef
fix fuzzerDirectedEdge build
Dec 24, 2021
ac4b918
Fix fuzzer programs
isaacbrodsky Dec 27, 2021
1145bce
remove logging
isaacbrodsky Dec 27, 2021
cd14266
remove h3Println
isaacbrodsky Dec 27, 2021
76532d8
add fuzzerPoylgonToCells
isaacbrodsky Jan 3, 2022
84bc4e9
Update per review
Jan 3, 2022
323d9e9
Merge branch 'master' into llvm-fuzzer-harness
Jan 3, 2022
e04c62c
Add comment on memcpy per review
Jan 3, 2022
0016f1c
Fix potential crash in vertexRotations
Jan 3, 2022
7807131
Merge branch 'master' into llvm-fuzzer-harness
Jan 3, 2022
4b4e623
Catch possible failure in getIcosahedronFaces
Jan 3, 2022
d501e51
Don't assert specific error in testVertex
Jan 3, 2022
d326156
Add polygonToCellsNoHoles fuzzer
Jan 11, 2022
558a37f
fix formatting
Jan 11, 2022
ffc3545
Merge branch 'master' into llvm-fuzzer-polygon-to-cells-2
Jan 17, 2022
c20e860
Mainly comment only changes
isaacbrodsky Jan 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ set(OTHER_SOURCE_FILES
src/apps/fuzzers/fuzzerDirectedEdge.c
src/apps/fuzzers/fuzzerLocalIj.c
src/apps/fuzzers/fuzzerPolygonToCells.c
src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c
src/apps/benchmarks/benchmarkPolygonToCells.c
src/apps/benchmarks/benchmarkPolygon.c
src/apps/benchmarks/benchmarkH3SetToLinkedGeo.c
Expand Down Expand Up @@ -678,6 +679,7 @@ if(BUILD_FUZZERS)
add_h3_fuzzer(fuzzerDirectedEdge src/apps/fuzzers/fuzzerDirectedEdge.c)
add_h3_fuzzer(fuzzerLocalIj src/apps/fuzzers/fuzzerLocalIj.c)
add_h3_fuzzer(fuzzerPolygonToCells src/apps/fuzzers/fuzzerPolygonToCells.c)
add_h3_fuzzer(fuzzerPolygonToCellsNoHoles src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c)
endif()

if(BUILD_BENCHMARKS)
Expand Down
6 changes: 4 additions & 2 deletions src/apps/fuzzers/fuzzerPolygonToCells.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef struct {
int res;
int numHoles;
// repeating: num verts, verts
// We add a large fixed buffer so our test case generator for AL
// We add a large fixed buffer so our test case generator for AFL
// knows how large to make the file.
uint8_t buffer[1024];
} inputArgs;
Expand Down Expand Up @@ -65,6 +65,8 @@ void run(GeoPolygon *geoPolygon, int res) {
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// TODO: It is difficult for the fuzzer to generate inputs that are
// considered valid by this fuzzer.
if (size < sizeof(inputArgs)) {
return 0;
}
Expand All @@ -77,7 +79,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
return 0;
}
geoPolygon.holes = calloc(geoPolygon.numHoles, sizeof(GeoLoop));
size_t offset = sizeof(inputArgs);
size_t offset = sizeof(inputArgs) - sizeof(args->buffer);
if (populateGeoLoop(&geoPolygon.geoloop, data, &offset, size)) {
free(geoPolygon.holes);
return 0;
Expand Down
61 changes: 61 additions & 0 deletions src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2022 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 polygonToCells and related functions, without holes
*/

#include "aflHarness.h"
#include "h3api.h"
#include "utility.h"

const int MAX_RES = 15;
const int MAX_SZ = 4000000;

void run(GeoPolygon *geoPolygon, int res) {
int64_t sz;
H3Error err = H3_EXPORT(maxPolygonToCellsSize)(geoPolygon, res, &sz);
if (!err && sz < MAX_SZ) {
if (sz < 0) {
// TODO: Check on this once rebased
printf("Oh no - sz is negative\n");
}
H3Index *out = calloc(sz, sizeof(H3Index));
H3_EXPORT(polygonToCells)(geoPolygon, res, out);
free(out);
}
}

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < sizeof(int)) {
return 0;
}

uint8_t res = *data;
size_t vertsSize = size - 1;
int numVerts = vertsSize / sizeof(LatLng);

GeoPolygon geoPolygon;
geoPolygon.numHoles = 0;
geoPolygon.holes = NULL;
geoPolygon.geoloop.numVerts = numVerts;
geoPolygon.geoloop.verts = (LatLng *)(data + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my info - why + 1? Oh, because the first uint_8 is the res? Might be worth a comment.

I imagine that most fuzzer runs would error quickly on an invalid res here, and never exercise the polyfill...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still better than fuzzerPoylgonToCells.c which is very difficult for the fuzzer to make progress on; here it only needs to guess one byte correctly (polygonToCells actually takes an int but I don't think that's quite as relevant) which I believe is very doable.


run(&geoPolygon, res);

return 0;
}

AFL_HARNESS_MAIN(sizeof(H3Index) * 1024);