-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode()
produces wrong value when low half of UUID is zero
#21
Comments
cpick
pushed a commit
to cpick/shortuuid
that referenced
this issue
May 14, 2021
Previously, `base57.numToString()` would use `number.Uint64()` which [is undefined](https://pkg.go.dev/math/big#Int.Uint64) if `number` "cannot be represented in a uint64" which is the case since it starts off containing a 128 bit integer. This would cause incorrect encoding of any UUID whose low half bits were all zero (along with any other cases where those bits were zero after some number of divisions by `b.alphabet.Length()`). The first added test shows an edge case that previously passed, the second an edge case that previously failed. Switch to using `big.Int.Cmp()` which works with any value. Fixes lithammer#21
cpick
pushed a commit
to cpick/shortuuid
that referenced
this issue
May 14, 2021
Previously, `base57.numToString()` would use `number.Uint64()` which [is undefined](https://pkg.go.dev/math/big#Int.Uint64) if `number` "cannot be represented in a uint64" which is the case since it starts off containing a 128 bit integer. This would cause incorrect encoding of any UUID whose low half bits were all zero (along with any other cases where those bits were zero after some number of divisions by `b.alphabet.Length()`). The first added test shows an edge case that previously passed, the second an edge case that previously failed. Switch to using `big.Int.Cmp()` which works with any value. Fixes lithammer#21
cpick
pushed a commit
to cpick/shortuuid
that referenced
this issue
May 14, 2021
Previously, `base57.numToString()` would use `number.Uint64()` which [is undefined](https://pkg.go.dev/math/big#Int.Uint64) if `number` "cannot be represented in a uint64" which is the case since it starts off containing a 128 bit integer. This would cause incorrect encoding of any UUID whose low half bits were all zero (along with any other cases where those bits were zero after some number of divisions by `b.alphabet.Length()`). The first added test shows an edge case that previously passed, the second an edge case that previously failed. Switch to using `big.Int.Cmp()` which works with any value. Fixes lithammer#21
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
base57.numToString()
usesnumber.Uint64()
which is undefined ifnumber
"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", but00000000-0000-0001-0000-000000000000
erroneously encodes to "2222222222222" which clashes with the encoding of00000000-0000-0000-0000-000000000000
as opposed to the expected "yDNELiVqLxt22".The text was updated successfully, but these errors were encountered: