diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c187f34..7bece31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -164,3 +164,27 @@ jobs: flags: ${{ steps.vars.outputs.CODECOV_FLAGS }} name: codecov-umbrella fail_ci_if_error: false + + fuzz: + name: Run the fuzzers + runs-on: ubuntu-latest + env: + RUN_FOR: 60 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - name: Install `cargo-fuzz` + run: cargo install cargo-fuzz + - uses: Swatinem/rust-cache@v2 + - name: Run from_str for XX seconds + shell: bash + run: | + ## Run it + cd fuzz + cargo +nightly fuzz run fuzz_from_str -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0 + - name: Run fuzz_parse_datetime_from_str for XX seconds + shell: bash + run: | + ## Run it + cd fuzz + cargo +nightly fuzz run fuzz_parse_datetime_from_str -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0 diff --git a/README.md b/README.md index 885c1f3..2680073 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ assert_eq!( ``` For DateTime parsing, import the `parse_datetime` module: -``` +```rs use humantime_to_duration::parse_datetime::from_str; use chrono::{Local, TimeZone}; diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index ce7cb9a..f6ed013 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -104,7 +104,7 @@ dependencies = [ [[package]] name = "humantime_to_duration" -version = "0.3.0" +version = "0.3.1" dependencies = [ "chrono", "regex", diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index de1f042..daaff8d 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -20,3 +20,9 @@ name = "fuzz_from_str" path = "fuzz_targets/from_str.rs" test = false doc = false + +[[bin]] +name = "fuzz_parse_datetime_from_str" +path = "fuzz_targets/parse_datetime_from_str.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/parse_datetime_from_str.rs b/fuzz/fuzz_targets/parse_datetime_from_str.rs new file mode 100644 index 0000000..2db587b --- /dev/null +++ b/fuzz/fuzz_targets/parse_datetime_from_str.rs @@ -0,0 +1,8 @@ +#![no_main] + +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + let s = std::str::from_utf8(data).unwrap_or(""); + let _ = humantime_to_duration::parse_datetime::from_str(s); +});