Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upNewV4: non-random uuid #73
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domino14
Apr 3, 2018
humans are bad at telling randomness. While it is extraordinarily, astronomically unlikely that you would have so many uuids with that many zeros, it is still theoretically possible.
domino14
commented
Apr 3, 2018
|
humans are bad at telling randomness. While it is extraordinarily, astronomically unlikely that you would have so many uuids with that many zeros, it is still theoretically possible. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
josselin-c
Apr 3, 2018
In an IDs such as 80730000-0000-4000-8000-000000000000 there are ~14 consecutive bytes of zeros.. While a probability of something like 1/2**(14*8) isn't nil, it's still too low for my taste. Drawing theses IDs 5 times out of ~1000 isn't just bad luck. In real life, if it was possible, I would start mining bitcoins with my super powers!
6e3ef1c8-0000-4000-8000-0000000000001
f7510000-0000-4000-8000-000000000000
0a14da92-0000-4000-8000-000000000000
80730000-0000-4000-8000-000000000000
cd2b88a5-0000-4000-8000-000000000000
I don't know the root cause of this.
josselin-c
commented
Apr 3, 2018
|
In an IDs such as
I don't know the root cause of this. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
peterstace
Apr 3, 2018
These UUIDs seem suspiciously non-random to me as well.
NewV4 gets its randomness from crypto/rand.Reader (and is basically a passthrough to populate a UUID). The code in NewV4 is really simple, I don't see how it could go wrong.
The only possibilities I can think of:
- There is a bug in
crypto/rand(seems unlikely). - Since
crypto/rand.Readeris just a variable, some malicious/accidental code could be swapping it out for a less randomio.Readerimplementation.
peterstace
commented
Apr 3, 2018
|
These UUIDs seem suspiciously non-random to me as well.
The only possibilities I can think of:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
josselin-c
Apr 4, 2018
Okay, I can reproduce it!
On my machine I have two separate processes: one webserver (ServerA) that calls uuid.Must(uuid.NewV4()).String() while simultaneously doing http requests to another webserver (ServerB) used for image resizing (imgproxy).
I instrumented ServerA with this code:
go func() {
for {
time.Sleep(1 * time.Second)
for i := 0; i < 1000; i++ {
u := uuid.Must(uuid.NewV4()).String()
if strings.Contains(u, "000000000") {
log.Fatal(u)
}
}
}
}()
Which runs without crashing if ServerA idle or handling standard requests. If ServerA is calling ServerB (to resize images), the ServerA immediately crash with a bad uuid.
I'll try to make a self-contained reproducer
josselin-c
commented
Apr 4, 2018
•
|
Okay, I can reproduce it! I instrumented ServerA with this code:
Which runs without crashing if ServerA idle or handling standard requests. If ServerA is calling ServerB (to resize images), the ServerA immediately crash with a bad uuid. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
josselin-c
Apr 4, 2018
Okay, I found the problem.
Here is the current NewV4 code:
// NewV4 returns random generated UUID.
func (g *rfc4122Generator) NewV4() (UUID, error) {
var err error
var c int
u := UUID{}
if _, err = g.rand.Read(u[:]); err != nil {
return Nil, err
}
u.SetVersion(V4)
u.SetVariant(VariantRFC4122)
return u, nil
}
Read() gives no guaranties about the number of bytes actually read. From https://golang.org/pkg/io/#Reader:
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered
Turns out, on some occasions Read would read less than len(u) bytes. I thinks uuid should use ReadFull instead of plain Read().
josselin-c
commented
Apr 4, 2018
|
Okay, I found the problem.
Turns out, on some occasions |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domino14
Apr 4, 2018
@josselin-c Could you make a patch and see if you can reproduce the error with your script and ReadFull? I wonder if using ReadFull would outright return an error in this case, because there aren't enough bytes to read.
domino14
commented
Apr 4, 2018
|
@josselin-c Could you make a patch and see if you can reproduce the error with your script and |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
domino14
Apr 4, 2018
One more thing that is interesting to me is the fact that the UUIDs you posted are not of equal length.
domino14
commented
Apr 4, 2018
|
One more thing that is interesting to me is the fact that the UUIDs you posted are not of equal length. |
pushed a commit
to josselin-c/go.uuid
that referenced
this issue
Apr 4, 2018
josselin-c
referenced a pull request that will
close
this issue
Apr 4, 2018
Open
Fix potential non-random UUIDs #75
jjjordanmsft
referenced this issue
May 8, 2018
Closed
uuid regression issue [multiple-value uuid.NewV4() in single-value context] #20
ajeddeloh
referenced this issue
May 17, 2018
Open
platform/azure: add kola/ore commands for Azure #771
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mikesun
Jun 1, 2018
So it looks like this commit introduced the bug: 0ef6afb
Prior to that commit, rand.Read() was used, which is a wrapper that uses io.ReadFull(): https://golang.org/pkg/crypto/rand/#Read
mikesun
commented
Jun 1, 2018
|
So it looks like this commit introduced the bug: 0ef6afb Prior to that commit, |
ajeddeloh
referenced this issue
Jun 18, 2018
Merged
Internal: Replaced hardcoded UUIDs with randomly generated UUIDs #560
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
CameronAckermanSEL
Jul 10, 2018
How is a critical bug like this still unresolved? Especially given that someone already did the work to fix it.
CameronAckermanSEL
commented
Jul 10, 2018
|
How is a critical bug like this still unresolved? Especially given that someone already did the work to fix it. |
This was referenced Jul 10, 2018
This was referenced Jul 11, 2018
added a commit
to josselin-c/awesome-go
that referenced
this issue
Jul 17, 2018
jiekang
referenced this issue
Jul 17, 2018
Open
fabric8-services/fabric8-wit, goadesign/goa and satori/go.uuid #4013
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
theckman
Jul 18, 2018
A few people in the Go community have banded together to adopt this package. We've just cut a v2.0.0 release of our fork: https://github.com/gofrs/uuid/releases/tag/v2.0.0
This is a GitHub organization with a few community members in it, so this package isn't being maintained by one individual. We're also available on the Gophers slack in #gofrs.
theckman
commented
Jul 18, 2018
|
A few people in the Go community have banded together to adopt this package. We've just cut a v2.0.0 release of our fork: https://github.com/gofrs/uuid/releases/tag/v2.0.0 This is a GitHub organization with a few community members in it, so this package isn't being maintained by one individual. We're also available on the Gophers slack in #gofrs. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rkuris
Jul 18, 2018
rkuris
commented
Jul 18, 2018
|
Awesome! Should I rebase my PR against this so it can be considered for
merging? It's been sitting for well over a year...
#50
…On Wed, Jul 18, 2018 at 12:58 PM Tim Heckman ***@***.***> wrote:
A few people in the Go community have banded together to adopt this
package. We've just cut a v2.0.0 release of our fork:
https://github.com/gofrs/uuid/releases/tag/v2.0.0
This is a GitHub organization with a few community members in it, so this
package isn't being maintained by one individual. We're also available on
the Gophers slack in #gofrs <https://gophers.slack.com/messages/CBP4N9BEU>
.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#73 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADC47O5rRxwr4XoRiROyRP6lZJDGFmifks5uH5NcgaJpZM4S5XdY>
.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
zerkms
Jul 18, 2018
@rkuris gofrs being an activists collaboration is open for any suggestions, as soon as we all can agree it adds value to the project
A required note: this is not an official position, just my personal understanding of the aim of the organisation.
zerkms
commented
Jul 18, 2018
|
@rkuris A required note: this is not an official position, just my personal understanding of the aim of the organisation. |
This was referenced Jul 19, 2018
This was referenced Jul 31, 2018
efritz
referenced this issue
Jul 31, 2018
Merged
Replace uses of satori/go.uuid with gofrs/uuid. #342
aarondl
referenced this issue
Aug 1, 2018
Closed
Error: (random.go) assignment mismatch: 2 variables but 1 values #355
michaljemala
referenced this issue
Aug 14, 2018
Merged
Ensure random part is always read from the entropy reader in full #28
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sethgrid
Aug 16, 2018
@josselin-c could you update the issue description and link to the new https://github.com/gofrs/uuid project?
sethgrid
commented
Aug 16, 2018
|
@josselin-c could you update the issue description and link to the new https://github.com/gofrs/uuid project? |
josselin-c commentedMar 23, 2018
•
edited
I'm running this on my macbook pro.
I'm using uuid.Must(uuid.NewV4()).String() to generate random identifiers. I'm generating theses identifiers at a very low rate of a few dozen per days
Here are some non-random UUID that I got in the last weeks:
I think I shouldn't have theses.