From 3a8b9e2a8456985b4b444be421e9f0f61b08b7f1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 3 Aug 2024 10:48:48 +0200 Subject: [PATCH 1/2] reproduce fuzzer failure in `gix-date` (#1485) --- gix-date/tests/time/parse.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gix-date/tests/time/parse.rs b/gix-date/tests/time/parse.rs index bf73395aa9e..545fbb7fc19 100644 --- a/gix-date/tests/time/parse.rs +++ b/gix-date/tests/time/parse.rs @@ -204,7 +204,7 @@ mod relative { mod fuzz { #[test] fn invalid_but_does_not_cause_panic() { - for input in ["7 -𬞋", "5 ڜ-09", "-4 week ago Z", "8960609 day ago"] { + for input in ["-9999-1-1", "7 -𬞋", "5 ڜ-09", "-4 week ago Z", "8960609 day ago"] { let _ = gix_date::parse(input, Some(std::time::UNIX_EPOCH)).unwrap_err(); } } From a729c4b52242b9a8b02f3d0879bd481f23a3d719 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 3 Aug 2024 10:57:30 +0200 Subject: [PATCH 2/2] fix: Don't panic on dates too far in the past when parsing them. (#1485) --- gix-date/src/parse.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gix-date/src/parse.rs b/gix-date/src/parse.rs index 449eea0ac87..376bdc0ba36 100644 --- a/gix-date/src/parse.rs +++ b/gix-date/src/parse.rs @@ -33,7 +33,9 @@ pub(crate) mod function { } Ok(if let Ok(val) = Date::strptime(SHORT.0, input) { - let val = val.to_zoned(TimeZone::UTC).expect("date is in range"); + let val = val + .to_zoned(TimeZone::UTC) + .map_err(|_| Error::InvalidDateString { input: input.into() })?; Time::new(val.timestamp().as_second(), val.offset().seconds()) } else if let Ok(val) = rfc2822_relaxed(input) { Time::new(val.timestamp().as_second(), val.offset().seconds())