lithammer / shortuuid

:mushroom: A generator library for concise, unambiguous and URL-safe UUIDs

Home Page:https://pkg.go.dev/github.com/lithammer/shortuuid/v4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Encode()` produces wrong value when low half of UUID is zero

cpick opened this issue · comments

base57.numToString() uses number.Uint64() which is undefined if number
"cannot be represented in a uint64" which is the case since it starts off containing a 128 bit integer.

This causes incorrect encoding of any UUID whose low half bits are all zero (along with any other cases where those bits were zero after some number of divisions by b.alphabet.Length()).

00000000-0000-0000-8000-000000000000 encodes to "z7C8BNkRBVT22", but 00000000-0000-0001-0000-000000000000 erroneously encodes to "2222222222222" which clashes with the encoding of 00000000-0000-0000-0000-000000000000 as opposed to the expected "yDNELiVqLxt22".