From 00e8108714a4395fb3fde0703ccda90a9d8d434a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 27 May 2026 16:59:21 +0100 Subject: [PATCH] Handle the case of a very large duration --- rust/src/duration.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/src/duration.rs b/rust/src/duration.rs index 9fb0048fd8..72a1027875 100644 --- a/rust/src/duration.rs +++ b/rust/src/duration.rs @@ -38,7 +38,10 @@ impl SynapseDuration { /// For now we only need to create durations from milliseconds. pub const fn from_milliseconds(milliseconds: u64) -> Self { Self { - microseconds: milliseconds * 1_000, + // We saturate at u64::MAX microseconds to avoid overflow, which + // means that the maximum duration we can represent is approximately + // 584,942 years. + microseconds: milliseconds.saturating_mul(1_000), } } }