From 569729b65c6500c1805098dd52e44792eac76d62 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 02:58:05 -0600 Subject: [PATCH] fix(id): fail world doctor clock check at or after 2100-01-01 (#3004) check_clock only tested now_ms > 0 while its doc comment promises absurd readings are caught: year 2100, year 3000 and u64::MAX all reported Ok. Add ABSURD_FUTURE_NOW_MS (4_102_444_800_000) next to check_clock: a reading at or after the bound is a Fail finding naming the reading and the bound, with the zero case fix text. Boundary tests: bound-1 Ok, bound Fail, u64::MAX Fail. --- pkgs/id/src/world_doctor.rs | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pkgs/id/src/world_doctor.rs b/pkgs/id/src/world_doctor.rs index 4b20bde88e..d7dc505273 100644 --- a/pkgs/id/src/world_doctor.rs +++ b/pkgs/id/src/world_doctor.rs @@ -396,11 +396,24 @@ pub fn validate_journal_file(path: &Path) -> Result<(usize, u32)> { Ok((entries, version.unwrap_or(JOURNAL_VERSION))) } +/// Milliseconds since the unix epoch at 2100-01-01T00:00:00Z. A clock +/// reading at or after this bound is absurd: no schedule or expiry this +/// doctor guards looks anywhere near that far ahead, so the reading can +/// only mean the system clock is wrong. +pub const ABSURD_FUTURE_NOW_MS: u64 = 4_102_444_800_000; + /// The clock reads a positive unix time. A zero (or absurd) reading means the /// system clock is before the epoch, which breaks every schedule and expiry. #[must_use] pub fn check_clock(inputs: &DoctorInputs) -> Finding { match inputs.now_ms { + Some(now) if now >= ABSURD_FUTURE_NOW_MS => fail( + "clock", + format!( + "the system clock reads {now} ms since the epoch, at or after the absurd-future bound of {ABSURD_FUTURE_NOW_MS} ms (2100-01-01T00:00:00Z)" + ), + "set the system clock (schedules and expiries depend on it)", + ), Some(now) if now > 0 => ok("clock", format!("{now} ms since the epoch")), _ => fail( "clock", @@ -657,4 +670,35 @@ mod tests { assert_eq!(check_clock(&inputs()).severity, Severity::Ok); } + + #[test] + fn a_clock_at_or_after_2100_fails() { + // One millisecond before the bound is still a plausible reading. + let just_before = check_clock(&DoctorInputs { + now_ms: Some(ABSURD_FUTURE_NOW_MS - 1), + ..inputs() + }); + assert_eq!(just_before.severity, Severity::Ok); + + // At the bound the reading is absurd and fails, naming both the + // reading and the bound, with the zero case's fix text. + let at_bound = check_clock(&DoctorInputs { + now_ms: Some(ABSURD_FUTURE_NOW_MS), + ..inputs() + }); + assert_eq!(at_bound.severity, Severity::Fail); + assert!(at_bound.detail.contains("4102444800000"), "{at_bound:#?}"); + assert!(at_bound.detail.contains("2100-01-01"), "{at_bound:#?}"); + assert_eq!( + at_bound.fix, + "set the system clock (schedules and expiries depend on it)" + ); + + // The largest possible reading fails too. + let max = check_clock(&DoctorInputs { + now_ms: Some(u64::MAX), + ..inputs() + }); + assert_eq!(max.severity, Severity::Fail); + } }