-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
633: Add first fuzz target for fuzzing simplify algorithm. r=michaelkirk a=frewsxcv - [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md). - ~I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.~ --- Based off of #532. Fuzzing allows us to find buggy edge cases and alsocheck the validity of our algorithms (by comparing results against the result of other libraries like GEOS). This pull request just adds one fuzz target for fuzzing our `Simplify` algorithm to get us started. How to fuzz: ```sh cargo install cargo-fuzz cd geo cargo fuzz run simplify # cargo fuzz run <fuzz target> ``` Co-authored-by: Corey Farwell <coreyf@rwell.org>
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
corpus | ||
artifacts |
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,29 @@ | ||
[package] | ||
name = "geo-fuzz" | ||
version = "0.0.0" | ||
authors = ["Automatically generated"] | ||
publish = false | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
|
||
[dependencies.geo] | ||
path = ".." | ||
|
||
[dependencies.geo-types] | ||
path = "../../geo-types" | ||
features = ["arbitrary"] | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "simplify" | ||
path = "fuzz_targets/simplify.rs" | ||
test = false | ||
doc = false |
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,23 @@ | ||
#![no_main] | ||
|
||
use geo::algorithm::euclidean_length::EuclideanLength; | ||
use geo::algorithm::simplify::Simplify; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!(|tuple: (geo_types::Polygon<f32>, f32)| { | ||
let (polygon, epsilon) = tuple; | ||
|
||
let simplified = polygon.simplify(&epsilon); | ||
|
||
check_result(polygon, simplified); | ||
}); | ||
|
||
fn check_result(original: geo_types::Polygon<f32>, simplified: geo_types::Polygon<f32>) { | ||
assert!(simplified.exterior().0.len() <= original.exterior().0.len()); | ||
assert!(simplified.exterior().euclidean_length() <= original.exterior().euclidean_length()); | ||
|
||
for interior in simplified.interiors() { | ||
assert!(simplified.exterior().0.len() <= interior.0.len()); | ||
assert!(simplified.exterior().euclidean_length() <= interior.euclidean_length()); | ||
} | ||
} |