Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix time 0.3 infinity panics#1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sfackler merged 3 commits intorust-postgres:masterfromallan2:time-overflow
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletionspostgres-types/src/time_03.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,7 +13,9 @@ fn base() -> PrimitiveDateTime {
impl<'a> FromSql<'a> for PrimitiveDateTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<PrimitiveDateTime, Box<dyn Error + Sync + Send>> {
let t = types::timestamp_from_sql(raw)?;
Ok(base() + Duration::microseconds(t))
Ok(base()
.checked_add(Duration::microseconds(t))
.ok_or("value too large to decode")?)
}

accepts!(TIMESTAMP);
Expand DownExpand Up@@ -62,7 +64,10 @@ impl ToSql for OffsetDateTime {
impl<'a> FromSql<'a> for Date {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Date, Box<dyn Error + Sync + Send>> {
let jd = types::date_from_sql(raw)?;
Ok(base().date() + Duration::days(i64::from(jd)))
Ok(base()
.date()
.checked_add(Duration::days(i64::from(jd)))
.ok_or("value too large to decode")?)
}

accepts!(DATE);
Expand Down
38 changes: 37 additions & 1 deletiontokio-postgres/tests/test/types/time_03.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
use std::fmt;

use postgres_types::FromSqlOwned;
use time_03::{format_description, OffsetDateTime, PrimitiveDateTime};
use tokio_postgres::types::{Date, Timestamp};
use tokio_postgres::{
types::{Date, Timestamp},
Client,
};

use crate::types::test_type;

Expand DownExpand Up@@ -147,3 +153,33 @@ async fn test_time_params() {
)
.await;
}

#[tokio::test]
async fn test_special_params_without_wrapper() {
async fn assert_overflows<T>(client: &mut Client, val: &str, sql_type: &str)
where
T: FromSqlOwned + fmt::Debug,
{
let err = client
.query_one(&*format!("SELECT {}::{}", val, sql_type), &[])
.await
.unwrap()
.try_get::<_, T>(0)
.unwrap_err();
assert_eq!(
err.to_string(),
"error deserializing column 0: value too large to decode"
);
}

let mut client = crate::connect("user=postgres").await;

assert_overflows::<OffsetDateTime>(&mut client, "'-infinity'", "timestamptz").await;
assert_overflows::<OffsetDateTime>(&mut client, "'infinity'", "timestamptz").await;

assert_overflows::<PrimitiveDateTime>(&mut client, "'-infinity'", "timestamp").await;
assert_overflows::<PrimitiveDateTime>(&mut client, "'infinity'", "timestamp").await;

assert_overflows::<time_03::Date>(&mut client, "'-infinity'", "date").await;
assert_overflows::<time_03::Date>(&mut client, "'infinity'", "date").await;
}

[8]ページ先頭

©2009-2025 Movatter.jp