my fork of dmp
| -rw-r--r-- | fuzz/.gitignore | 4 | ||||
| -rw-r--r-- | fuzz/Cargo.toml | 21 | ||||
| -rw-r--r-- | fuzz/fuzz_targets/fuzz_target.rs | 8 | ||||
| -rw-r--r-- | src/fuzz.rs | 19 | ||||
| -rw-r--r-- | src/lib.rs | 1 |
5 files changed, 53 insertions, 0 deletions
diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..1a45eee --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ +target +corpus +artifacts +coverage diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..c809905 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "diff-match-patch-rs-fuzz" +version = "0.0.0" +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.diff-match-patch-rs] +path = ".." + +[[bin]] +name = "fuzz_target" +path = "fuzz_targets/fuzz_target.rs" +test = false +doc = false +bench = false diff --git a/fuzz/fuzz_targets/fuzz_target.rs b/fuzz/fuzz_targets/fuzz_target.rs new file mode 100644 index 0000000..5819764 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_target.rs @@ -0,0 +1,8 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: (&str, &str)| { + // fuzzed code goes here + diff_match_patch_rs::fuzz::fuzz(data.0, data.1).unwrap(); +}); diff --git a/src/fuzz.rs b/src/fuzz.rs new file mode 100644 index 0000000..0beedb3 --- /dev/null +++ b/src/fuzz.rs @@ -0,0 +1,19 @@ +use crate::{Compat, DiffMatchPatch, Efficient, Error, PatchInput}; + +pub fn fuzz(old: &str, new: &str) -> Result<(), Error> { + let dmp = DiffMatchPatch::new(); + + let diffs = dmp.diff_main::<Efficient>(old, new)?; + let patches = dmp.patch_make(PatchInput::new_diffs(&diffs))?; + + assert_eq!(new, dmp.patch_apply(&patches, old)?.0); + + let dmp = DiffMatchPatch::new(); + + let diffs = dmp.diff_main::<Compat>(old, new)?; + let patches = dmp.patch_make(PatchInput::new_diffs(&diffs))?; + + assert_eq!(new, dmp.patch_apply(&patches, old)?.0); + + Ok(()) +} @@ -2,6 +2,7 @@ pub mod dmp; pub mod errors; +pub mod fuzz; pub mod patch_input; pub mod traits; |