Ticket #3971 (closed Patches: fixed)

Opened 4 years ago

Last modified 4 years ago

basic_random_generator doesn't produce a fully randomized uuid when sizeof(unsigned long) == 4

Reported by: gareth.sylvester-bradley@… Owned by: atompkins
Milestone: Boost 1.43.0 Component: uuid
Version: Boost 1.42.0 Severity: Showstopper
Keywords: Cc:


There is a flaw in basic_random_generator<> (boost/uuid/uuid_generators.hpp, line 366-374) that means it will only generate about 4 billion different values before a collision on the many platforms where sizeof(unsigned long) == 4.

On these platforms the first 8 bytes of the uuid are populated with random data, but the contents of the remaining 8 bytes are undefined.

In my tests they are populated with repeated data, due to Microsoft's specific implementation for the undefined behaviour of >> when its "right operand is greater than or equal to the length in bits of the promoted left operand."

For example, try the following test program with a Win32 build by Visual C++ 9.0 –

#include <iostreams>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

int main( int, char*[] )
  std::cout << boost::uuids::random_generator()() << std::endl;
  return 0;

This produced for me:


Or wrapped to show the problem:

ee94 37b9

The simplest patch could be just:

>                 i=0;


Change History

comment:1 Changed 4 years ago by dave

  • Severity changed from Problem to Showstopper

comment:2 Changed 4 years ago by atompkins

  • Status changed from new to closed
  • Resolution set to fixed

Fixed as suggested in both trunk and merged into release.


Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.