From dc508c469b22c620369a36b0295edd92cd3d4729 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 7 Jun 2023 13:51:40 +0200 Subject: [PATCH 1/3] add a fuzzer for parse_datetime_from_str --- fuzz/Cargo.lock | 2 +- fuzz/Cargo.toml | 6 ++++++ fuzz/fuzz_targets/parse_datetime_from_str.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 fuzz/fuzz_targets/parse_datetime_from_str.rs 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); +}); From 22bdd8f49ca65b4e6e54ae4e4754840bc6883d4f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 7 Jun 2023 13:52:00 +0200 Subject: [PATCH 2/3] run the fuzzers in the CI --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 From 80f8fdf8834d18de9d61d2fcb708ebd0fbe796aa Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 7 Jun 2023 15:01:25 +0200 Subject: [PATCH 3/3] README: syntax highlighting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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};