Skip to content
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

Fix Issue 19836 - Excessive probability of UUID collisions in std.uuid.randomUUID #6985

Merged
merged 1 commit into from Apr 29, 2019

Conversation

n8sh
Copy link
Member

@n8sh n8sh commented Apr 28, 2019

On 64-bit architectures use 64 bits of entropy to initialize thread-local rndGen.

The motivation for this change is std.uuid defaults to using rndGen to generate UUIDs. If every rndGen starts in one of 2^^32 states then if 77000 independent programs each generate a single UUID there is a 50% chance that at least two of them generate the same initial UUID (and all subsequent UUIDs would be identical as well). Not just Phobos but also C++ boost::uuids::random_generator defaults to generating UUIDs with a Mersenne Twister initialized from a 32-bit seed, exacerbating the collision problem further. If instead there are 2^^64 possible initial states of rndGen there can be over 5 billion independent rndGens before there is a 50% chance of two having identical initial states.

This change is limited to 64-bit architectures to avoid a measurable performance decrease, because many programs are not generating UUIDs.

@n8sh n8sh requested a review from wilzbach as a code owner April 28, 2019 19:10
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @n8sh!

Bugzilla references

Auto-close Bugzilla Severity Description
19836 normal Excessive probability of UUID collisions in std.uuid.randomUUID

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + phobos#6985"

…d.randomUUID

On 64-bit architectures use 64 bits of entropy to initialize
thread-local `rndGen`.

The motivation for this change is std.uuid defaults to using `rndGen`
to generate UUIDs. If every `rndGen` starts in one of 2^^32 states then
if 77000 independent programs each generate a single UUID there is a 50%
chance that at least two of them generate the same initial UUID (and all
subsequent UUIDs would be identical as well). Not just Phobos but also
C++ boost::uuids::random_generator defaults to generating UUIDs with a
Mersenne Twister initialized from a 32-bit seed, exacerbating the
collision problem further. If instead there are 2^^64 possible initial
states of `rndGen` there can be over 5 billion independent `rndGen`s
before there is a 50% chance of two having identical initial states.

This change is limited to 64-bit architectures to avoid a measurable
performance decrease, because many programs are not generating UUIDs.
Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose a test is out of the question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants