bwmarrin / snowflake

A simple to use Go (golang) package to generate or parse Twitter snowflake IDs
BSD 2-Clause "Simplified" License
2.98k stars 371 forks source link

parsing doesn't consider negative numbers #42

Open ssoroka opened 2 years ago

ssoroka commented 2 years ago

using ParseBase58 as an example, values should round-trip properly back to their original value, or error.

ok := "npL6MjP8Qfc"   //0x7fffffffffffffff
bad1 := "npL6MjP8Qfd" //0x7fffffffffffffff + 1 // overflows int64 and becomes negative
bad2 := "JPwcyDCgEuq" //0xffffffffffffffff + 1 // overflows uint64 and wraps back to 1

These issues can come up when accepting requests with bad IDs from clients, and they should not be accepted as valid ids.

bwmarrin commented 1 year ago

Thanks for finding and reporting this :)

I think a good safe initial fix would be to check for this and error on it.