-
Notifications
You must be signed in to change notification settings - Fork 462
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
Polygon to cells experimental fuzzer #800
Open
isaacbrodsky
wants to merge
45
commits into
uber:master
Choose a base branch
from
isaacbrodsky:polygon-to-cells-experimental-fuzzer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
de71b07
Add support for full containment mode in polygonToCells
45255d5
Add tests
61d3e5b
Implement OVERLAPPING mode, update tests to use mode flags
585f497
Rename containment enum values
1a44627
Fix and test for case where OVERLAPPING cell contains polygon
edaa901
Possibly fix test
fedaa5f
Fixture fix
b3eb114
add polygonToCellsExperimental fuzzers
isaacbrodsky a2adc04
Additional test coverage for error cases
f0f1b45
Test coverage for one more error, excluding unreachable block from co…
06ca7c0
Merge branch 'polyfill-contained' into polygon-to-cells-experimental-…
isaacbrodsky 4226e43
fix fuzzer comment
isaacbrodsky da85fe5
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky b055cd5
fix size estimation
isaacbrodsky 674b427
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 629c654
add test
isaacbrodsky 641d481
add null test
isaacbrodsky 7659732
add TODO
isaacbrodsky 4f0341c
guard against numVerts = 0 for hole check
isaacbrodsky c6a21b8
add empty with null hole test
isaacbrodsky 3975ff9
update test
isaacbrodsky cfe8816
actually cover
isaacbrodsky 6730469
add fuzzer derived test case
isaacbrodsky 29a9b01
simplify
isaacbrodsky 85d5641
year
isaacbrodsky 5ac48c5
actually pass flags
isaacbrodsky 2778c08
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 8f00a0b
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 377777b
attempted fix
isaacbrodsky e25e8fa
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 48f064e
remove ineffective fix
isaacbrodsky b4370cb
fix inequality
isaacbrodsky 1c4cef0
fix for 0 length maxes
isaacbrodsky 74f206e
fix memory test
isaacbrodsky 572325c
fix for overlapping bbox inconsistency
isaacbrodsky 942a54b
revert check
isaacbrodsky 9b51221
revert memory test
isaacbrodsky 9417bb0
more overlapping bbox changes
isaacbrodsky 08bc56e
change assert to avoid triggering in test
isaacbrodsky 6048f36
remove tests with unaligned reads
isaacbrodsky 21c5a65
ignore extra build directories
isaacbrodsky c256faa
comment
isaacbrodsky 2742464
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 9dbea70
back out unneeded change
isaacbrodsky 0b4f284
Merge branch 'master' into polygon-to-cells-experimental-fuzzer
isaacbrodsky 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 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 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 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 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 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,106 @@ | ||
/* | ||
* Copyright 2023 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 polygonToCells2 and related functions | ||
*/ | ||
|
||
#include "aflHarness.h" | ||
#include "h3api.h" | ||
#include "polyfill.h" | ||
#include "polygon.h" | ||
#include "utility.h" | ||
|
||
typedef struct { | ||
int res; | ||
int numHoles; | ||
// repeating: num verts, verts | ||
// 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; | ||
|
||
const int MAX_RES = 15; | ||
const int MAX_SZ = 4000000; | ||
const int MAX_HOLES = 100; | ||
|
||
int populateGeoLoop(GeoLoop *g, const uint8_t *data, size_t *offset, | ||
size_t size) { | ||
if (size < *offset + sizeof(int)) { | ||
return 1; | ||
} | ||
int numVerts = *(const int *)(data + *offset); | ||
*offset = *offset + sizeof(int); | ||
g->numVerts = numVerts; | ||
if (size < *offset + sizeof(LatLng) * numVerts) { | ||
return 1; | ||
} | ||
g->verts = (LatLng *)(data + *offset); | ||
*offset = *offset + sizeof(LatLng) * numVerts; | ||
return 0; | ||
} | ||
|
||
void run(GeoPolygon *geoPolygon, uint32_t flags, int res) { | ||
int64_t sz; | ||
H3Error err = H3_EXPORT(maxPolygonToCellsSizeExperimental)(geoPolygon, res, | ||
flags, &sz); | ||
if (!err && sz < MAX_SZ) { | ||
H3Index *out = calloc(sz, sizeof(H3Index)); | ||
H3_EXPORT(polygonToCellsExperimental)(geoPolygon, res, flags, out); | ||
free(out); | ||
} | ||
} | ||
|
||
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. fuzzerPolygonToCellsNoHoles.c | ||
// is a workaround for that. | ||
if (size < sizeof(inputArgs)) { | ||
return 0; | ||
} | ||
const inputArgs *args = (const inputArgs *)data; | ||
int res = args->res % (MAX_RES + 1); | ||
|
||
GeoPolygon geoPolygon; | ||
int originalNumHoles = args->numHoles % MAX_HOLES; | ||
geoPolygon.numHoles = originalNumHoles; | ||
if (geoPolygon.numHoles < 0) { | ||
return 0; | ||
} | ||
geoPolygon.holes = calloc(geoPolygon.numHoles, sizeof(GeoLoop)); | ||
size_t offset = sizeof(inputArgs) - sizeof(args->buffer); | ||
if (populateGeoLoop(&geoPolygon.geoloop, data, &offset, size)) { | ||
free(geoPolygon.holes); | ||
return 0; | ||
} | ||
for (int i = 0; i < geoPolygon.numHoles; i++) { | ||
if (populateGeoLoop(&geoPolygon.holes[i], data, &offset, size)) { | ||
free(geoPolygon.holes); | ||
return 0; | ||
} | ||
} | ||
|
||
for (uint32_t flags = 0; flags < CONTAINMENT_INVALID; flags++) { | ||
geoPolygon.numHoles = originalNumHoles; | ||
run(&geoPolygon, flags, res); | ||
geoPolygon.numHoles = 0; | ||
run(&geoPolygon, flags, res); | ||
} | ||
free(geoPolygon.holes); | ||
|
||
return 0; | ||
} | ||
|
||
AFL_HARNESS_MAIN(sizeof(inputArgs)); |
64 changes: 64 additions & 0 deletions
64
src/apps/fuzzers/fuzzerPolygonToCellsExperimentalNoHoles.c
This file contains 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,64 @@ | ||
/* | ||
* Copyright 2023 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 polygonToCellsExperimental and related functions, | ||
* without holes | ||
*/ | ||
|
||
#include "aflHarness.h" | ||
#include "h3api.h" | ||
#include "polyfill.h" | ||
#include "polygon.h" | ||
#include "utility.h" | ||
|
||
const int MAX_RES = 15; | ||
const int MAX_SZ = 4000000; | ||
|
||
void run(GeoPolygon *geoPolygon, uint32_t flags, int res) { | ||
int64_t sz; | ||
H3Error err = H3_EXPORT(maxPolygonToCellsSizeExperimental)(geoPolygon, res, | ||
flags, &sz); | ||
if (!err && sz < MAX_SZ) { | ||
H3Index *out = calloc(sz, sizeof(H3Index)); | ||
H3_EXPORT(polygonToCellsExperimental)(geoPolygon, res, flags, 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; | ||
// Offset by 1 since *data was used for `res`, above. | ||
geoPolygon.geoloop.verts = (LatLng *)(data + 1); | ||
|
||
for (uint32_t flags = 0; flags < CONTAINMENT_INVALID; flags++) { | ||
run(&geoPolygon, flags, res); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
AFL_HARNESS_MAIN(sizeof(H3Index) * 1024); |
This file contains 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
Should this be changed to 0 or 1 returns nothing? @nrabinowitz
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 think the case for 1 and 2 vertexes is equivalent - in both cases, we have input that cannot be a 2D polygon, and we either have to discard it or treat it like a shape. While it's obviously a pathological case, I think it would be reasonable to assume that If you have a one-vertex "polygon" and you use
CONTAINMENT_OVERLAPPING
that you'd get the cell that contains the point. There's also a potential use case for line segments in the 2-vertex case. I'm also concerned that the estimate and the implementation don't line up.Should I take a shot at a PR to fix this, which we can land before this one?
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 agree that seems like the expected behavior, if you have an idea for addressing please take a look.
I can help apply these tests to another branch to help validate.