Timestamp::from_rfc4122 panics when using timestamp before unix epoch #680
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#680
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Timestamp::from_rfc4122method panics withattempt to subtract with overflowerror when passing ticks value less thanUUID_TICKS_BETWEEN_EPOCHS.I'm not sure that the intentional use of a UUID with the wrong timestamp can be considered acceptable by the standard. But even if this is considered unacceptable, a
# Panicssection describing that theTimestamp::from_rfc4122method panics at certain values would be useful in method description.The UUID crate allowed these values up to and including version
1.1.2. In UUIDv1.1.2the timestamp stored RFC4122 ticks. After UUIDv1.2.1Timestamp started to use unix time instead.Code from the UUID crate for reference:
github.com/uuid-rs/uuid@6188ecf96c/src/timestamp.rs (L25-L27)github.com/uuid-rs/uuid@6188ecf96c/src/timestamp.rs (L75-L89)github.com/uuid-rs/uuid@6188ecf96c/src/timestamp.rs (L133-L138)Thanks for the report @zheland. I think we've got two options here:
Do either of those options appeal to you more than the other?
@KodrAus,
UUIDv1andUUIDv6. However, if considering that the use of incorrect time is rather wrong, then this option is basically completely fine.Pros:
UUIDv1will support any valid rfc4122 timestamp andUUIDv7will support any valid unix timestamp.Cons: Possible silent wrapping operations when using invalid unix time to generate
UUIDv1or silent wrapping operations when using invalid rfc4122 to generateUUIDv7. If mentioned in the documentation it looks quite tolerable behavior.I’m also more inclined to a non-panicking variant here. For anybody that’s concerned about quietly changing behaviour through wrapping or truncation we can offer a
checked_from_rfc4122that returns anOption.I do like that the wrapping variant gives you a more uniquely useful timestamp. I’d be happy with an implementation that did that. It might also be worth checking the current draft spec that introduces v6-v8 and see if it recommends any behaviour converting RRC4122 timestamps to Unix time.
Thanks @zheland 👍 I've opened #691 that addresses this by explicitly wrapping, basically as you've suggested here. All we're guaranteeing is that those methods won't panic, not that they'll wrap to any particular value, so I've reflected that in the test by only ensuring overflowing inputs don't panic.