From 8d7334fc9b41f1686ca5d265d92a1294b075f666 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 22 Aug 2026 15:40:55 +0530 Subject: [PATCH] fix(temporal): avoid byte-index panic on non-UTF-8-boundary input parse_timestamp sliced s[10..] to check for a timezone offset dash, which panics when byte 10 falls inside a multi-byte UTF-8 character. The nightly fuzz workflow found this via datalog_eval on :as-of query strings containing non-ASCII characters (fuzz/artifacts/datalog_eval/ crash-012232f88967026da67f1548a7d90910f6134d8a). Use s.get(10..) instead, which returns None on out-of-range or non-boundary indices rather than panicking. Fixes #319 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YMWSutMLJJ7Y5b8hs9ZaCU --- .../seed_temporal_multibyte_char_boundary.bin | 1 + src/temporal.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 fuzz/corpus/datalog_eval/seed_temporal_multibyte_char_boundary.bin diff --git a/fuzz/corpus/datalog_eval/seed_temporal_multibyte_char_boundary.bin b/fuzz/corpus/datalog_eval/seed_temporal_multibyte_char_boundary.bin new file mode 100644 index 0000000000..6bd91394ad --- /dev/null +++ b/fuzz/corpus/datalog_eval/seed_temporal_multibyte_char_boundary.bin @@ -0,0 +1 @@ +(query [:::as-of"f[r[Y[[r[؅f"n_1]) diff --git a/src/temporal.rs b/src/temporal.rs index cde12de21e..cf2396e486 100644 --- a/src/temporal.rs +++ b/src/temporal.rs @@ -16,7 +16,7 @@ use chrono::{DateTime, NaiveDate, TimeZone, Utc}; /// - Any string with a timezone offset (e.g., `+05:30`) — use UTC (Z) only. pub fn parse_timestamp(s: &str) -> Result { // Reject timezone offsets explicitly - if s.contains('+') || (s.len() > 10 && s[10..].contains('-')) { + if s.contains('+') || s.get(10..).is_some_and(|rest| rest.contains('-')) { return Err(anyhow!( "timezone offsets are not supported; use UTC (Z) timestamps only. \ chrono's local timezone handling (GHSA-wcg3-cvx6-7396) is avoided by design." @@ -91,6 +91,14 @@ mod tests { assert!(parse_timestamp("not-a-date").is_err()); } + #[test] + fn test_multibyte_char_near_byte_offset_10_does_not_panic() { + // Byte offset 10 falls inside the 2-byte UTF-8 encoding of '\u{605}', + // which starts at byte 9. Slicing s[10..] would panic on a non-char-boundary. + let s = "123456789\u{605}abc"; + assert!(parse_timestamp(s).is_err()); + } + #[test] fn test_millis_to_timestamp_roundtrip() { let original = "2024-01-15T10:00:00Z";