Skip to content

fix: reject timestamps outside 32-bit ObjectID range#115

Open
leno23 wants to merge 1 commit into
rs:masterfrom
leno23:fix/newwithtime-timestamp-range-107
Open

fix: reject timestamps outside 32-bit ObjectID range#115
leno23 wants to merge 1 commit into
rs:masterfrom
leno23:fix/newwithtime-timestamp-range-107

Conversation

@leno23

@leno23 leno23 commented May 17, 2026

Copy link
Copy Markdown

Summary

Fixes #107

NewWithTime previously cast t.Unix() to uint32, so times beyond 2^32-1 seconds (or before the Unix epoch) produced IDs whose Time() did not round-trip.

  • Add NewWithTimeE returning ErrTimestampOutOfRange when t.Unix() is out of range
  • NewWithTime delegates to NewWithTimeE and panics on error (same style as other fatal misconfiguration in this package)

Test plan

  • go test ./...
  • Round-trip at maxTimestamp, error on overflow and negative times

Fixes rs#107 by validating Unix seconds in NewWithTimeE instead of
silently truncating. NewWithTime panics on out-of-range times, matching
other fatal misconfiguration paths in the package.
@leno23 leno23 force-pushed the fix/newwithtime-timestamp-range-107 branch from 7d1891d to 6ad82eb Compare May 17, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: NewWithTime uint wrap around causes xid to return wrong time

1 participant