Skip to content

Commit

Permalink
Merge #633
Browse files Browse the repository at this point in the history
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
bors[bot] and frewsxcv committed Feb 26, 2021
2 parents 54c09a4 + dd4139d commit ab95865
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- geo_types
- geo
- geo_postgis
- geo_fuzz
- coverage
- bench
steps:
Expand All @@ -24,6 +25,7 @@ jobs:
- name: Mark the job as a failure
if: "!success()"
run: exit 1

geo_types:
name: geo-types
runs-on: ubuntu-latest
Expand Down Expand Up @@ -80,6 +82,24 @@ jobs:
- run: cargo install cargo-all-features
- run: cargo build-all-features
- run: cargo test-all-features

geo_fuzz:
name: geo-fuzz
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
defaults:
run:
working-directory: geo/fuzz
strategy:
matrix:
container_image: ["georust/geo-ci:rust-1.49", "georust/geo-ci:rust-1.50"]
container:
image: ${{ matrix.container_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- run: cargo build --bins

coverage:
name: coverage
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions geo/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
corpus
artifacts
29 changes: 29 additions & 0 deletions geo/fuzz/Cargo.toml
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
23 changes: 23 additions & 0 deletions geo/fuzz/fuzz_targets/simplify.rs
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());
}
}

0 comments on commit ab95865

Please sign in to comment.