Don't panic when the nanoseconds carry overflows the seconds #911
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!911
Loading…
Reference in a new issue
No description provided.
Delete branch "youdie006/systemtime-nanos-carry"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #908 and #909.
#909 guarded the outer add, but
Duration::new(seconds, subsec_nanos)is evaluated first and panics on its own when the nanoseconds carry pastu64::MAXseconds.Timestamp::from_unix_timeis apub const fntaking a rawu32, so anysubsec_nanos >= 1_000_000_000reaches it, the same entry point #908 used:The doc at
src/timestamp.rs:225-228says an undefinedSystemTimeis returned rather than a failure, so this builds theDurationfrom its parts with the samechecked_* -> unwrap_or(UNIX_EPOCH)shape #909 used, one level inward.Verification
Base
9f92712.src/timestamp.rsmd5from_system_time_maxfrom_system_time_nanos_carryf23cc9e47827d00ed6101da1e439e27502b0bb61The first row is the point: the test #909 added still passes on base while the new one fails. The last two rows are killed by different tests, so neither guard is redundant, and the over-correction is caught by the
(10, 2_500_000_000) -> 12.5sassertion, so a clamp-everything fix would not pass either.cargo test --all-features0 failures;cargo +1.85.0 build --manifest-path tests/smoke-test/Cargo.tomlclean;cargo +beta clippy --all-featuresreports the same 4 warnings before and after, none at the changed lines.Not run, and not claimed: the
miri, wasm, wasi, embedded and fuzz jobs. The pinned nightly and those toolchains are not available on my machine. The change is safe arithmetic inside#[cfg(feature = "std")], so the no-std jobs do not compile it at all.One thing I left alone:
src/timestamp.rs:228points callers atTryFromto catch conversion failures, but there is no fallibleTryFrom<Timestamp> for SystemTime. That seemed like separate scope.Disclosure: written with the help of Claude (an AI assistant). Every number above is from runs on my machine.
The bug here I think is that we accept a timestamp with nanos that overflow a second at all. I think it would be reasonable to panic here, just like
Duration::newdoes.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.