Skip to content

panic in ZonedDateTime::strptime when parsing a time string very near boundary, with a timezone offset #718

Closed

Description

@Benjins

Repro:

use jiff::ZonedDateTime;

#[test]
fn test_zdt_01() {
        let _ = ZonedDateTime::strptime("%F %T %z %Q", "9999-12-31 23:59:59 +0900 Asia/Tokyo");
}

#[test]
fn test_zdt_02() {
        let _ = ZonedDateTime::strptime("%F %T %::z %Q", "-9999-01-01 00:00:00 -04:56:02 America/New_York");
}

I verified this repros on the 1.01 release, and the latest trunk (1672f05)

test 1:

thread 'test_zdt_01' (3713135) panicked at /z/jiff-1.0.1/src/fmt/strtime/mod.rs:1543:54:
called `Result::unwrap()` on an `Err` value: error converting datetime to instant in time zone Asia/Tokyo: converting datetime with time zone offset `+09` to timestamp overflowed: parameter 'Unix timestamp seconds' is not in the required range of -377705023201..=253402207200

test 2:

thread 'test_zdt_02' (3713136) panicked at /z/jiff-1.0.1/src/fmt/strtime/mod.rs:1543:54:
called `Result::unwrap()` on an `Err` value: error converting datetime to instant in time zone America/New_York: converting datetime with time zone offset `-04:56:02` to timestamp overflowed: parameter 'Unix timestamp seconds' is not in the required range of -377705023201..=253402207200

It looks to be the code here, and I assume the unwrap() is not guaranteed to pass in the case of overflow:

// Guaranteed that if OffsetConflict::Reject doesn't
// reject, then we get back an unambiguous zoned
// datetime.
let zdt = azdt.unambiguous().unwrap();
Ok(zdt)

For disclosure: this bug was originally found by an LLM and fuzz-testing, but I have manually confirmed it and the report here is my own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions