launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.32k stars 1.27k forks source link

Panic on Postgres `-infinity` timestamp #2234

Open andrewbaxter opened 1 year ago

andrewbaxter commented 1 year ago

Bug Description

Reading a row with a timestamp with value -infinity results in a panic:

thread 'tokio-runtime-worker' panicked at '`NaiveDateTime + Duration` overflowed', /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.22/src/naive/datetime/mod.rs:1281:38
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
   2: core::panicking::panic_display
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:72:5
   3: core::panicking::panic_str
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:1874:5
   5: core::option::Option<T>::expect
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:738:21
   6: <chrono::naive::datetime::NaiveDateTime as core::ops::arith::Add<time::duration::Duration>>::add
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/chrono-0.4.22/src/naive/datetime/mod.rs:1281:9
   7: sqlx_core::postgres::types::chrono::datetime::<impl sqlx_core::decode::Decode<sqlx_core::postgres::database::Postgres> for chrono::naive::datetime::NaiveDateTime>::decode
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-core-0.6.2/src/postgres/types/chrono/datetime.rs:61:17
   8: sqlx_core::row::Row::try_get_unchecked
             at /home/.../.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-core-0.6.2/src/row.rs:159:9

Minimal Reproduction

TBA

Info

andrewbaxter commented 1 year ago

TBH I was just expecting it to return the epoch (or earliest valid chrono timestamp), but I guess there may be use cases where a panic might uncover bugs with software dealing with early history times.