From 6c2c75a0a602e2c5c25918130befb0d61a18aaaf Mon Sep 17 00:00:00 2001 From: Yoshiki Takashima Date: Fri, 29 Jul 2022 11:43:35 -0400 Subject: [PATCH] Permit overflow with wrapping. (#686) --- prost-types/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/prost-types/src/lib.rs b/prost-types/src/lib.rs index 086cdbb51..223bd1aa9 100644 --- a/prost-types/src/lib.rs +++ b/prost-types/src/lib.rs @@ -368,8 +368,13 @@ impl TryFrom for std::time::SystemTime { let system_time = if timestamp.seconds >= 0 { std::time::UNIX_EPOCH.checked_add(time::Duration::from_secs(timestamp.seconds as u64)) } else { - std::time::UNIX_EPOCH - .checked_sub(time::Duration::from_secs((-timestamp.seconds) as u64)) + std::time::UNIX_EPOCH.checked_sub(time::Duration::from_secs( + timestamp + .seconds + .checked_neg() + .ok_or(TimestampError::OutOfSystemRange(timestamp.clone()))? + as u64, + )) }; let system_time = system_time.and_then(|system_time| {