@@ -42,9 +42,6 @@ namespace boost { namespace interprocess { namespace detail {} namespace ipcdeta
4242#endif
4343#endif // OPENVDB_USE_DELAYED_LOADING
4444
45- #include < boost/uuid/uuid_generators.hpp>
46- #include < boost/uuid/uuid_io.hpp>
47-
4845#include < atomic>
4946
5047#include < algorithm> // for std::find_if()
@@ -608,7 +605,7 @@ getErrorString()
608605Archive::Archive ()
609606 : mFileVersion (OPENVDB_FILE_VERSION)
610607 , mLibraryVersion (OPENVDB_LIBRARY_MAJOR_VERSION, OPENVDB_LIBRARY_MINOR_VERSION)
611- , mUuid (boost::uuids::nil_uuid() )
608+ , mUuid ()
612609 , mInputHasGridOffsets (false )
613610 , mEnableInstancing (true )
614611 , mCompression (DEFAULT_COMPRESSION_FLAGS)
@@ -635,13 +632,17 @@ Archive::copy() const
635632std::string
636633Archive::getUniqueTag () const
637634{
638- return boost::uuids::to_string ( mUuid ) ;
635+ return mUuid ;
639636}
640637
641638
642639bool
643640Archive::isIdentical (const std::string& uuidStr) const
644641{
642+ // If either uuids are blank, they will always fail to match
643+ // as something went wrong generating them.
644+ if (uuidStr.empty ()) return false ;
645+ if (getUniqueTag ().empty ()) return false ;
645646 return uuidStr == getUniqueTag ();
646647}
647648
@@ -1013,16 +1014,37 @@ Archive::readHeader(std::istream& is)
10131014 }
10141015
10151016 // 6) Read the 16-byte (128-bit) uuid.
1016- boost::uuids::uuid oldUuid = mUuid ;
1017+ std::string oldUuid = mUuid ;
10171018 if (mFileVersion >= OPENVDB_FILE_VERSION_BOOST_UUID) {
1018- // UUID is stored as an ASCII string.
1019- is >> mUuid ;
1019+ // UUID is stored as fixed-length ASCII string
1020+ // The extra 4 bytes are for the hyphens.
1021+ char uuidValues[16 *2 +4 +1 ];
1022+ is.read (uuidValues, 16 *2 +4 );
1023+ uuidValues[16 *2 +4 ] = 0 ;
1024+ mUuid = uuidValues;
10201025 } else {
10211026 // Older versions stored the UUID as a byte string.
10221027 char uuidBytes[16 ];
10231028 is.read (uuidBytes, 16 );
1024- std::memcpy (&mUuid .data [0 ], uuidBytes, std::min<size_t >(16 , mUuid .size ()));
1029+ char uuidStr[33 ];
1030+ auto to_hex = [](unsigned int c) -> char
1031+ {
1032+ c &= 0xf ;
1033+ if (c < 10 ) return (char )(' 0' + c);
1034+ return (char )(c - 10 + ' A' );
1035+ };
1036+ for (int i = 0 ; i < 16 ; i++)
1037+ {
1038+ uuidStr[i*2 ] = to_hex (uuidBytes[i] >> 4 );
1039+ uuidStr[i*2 +1 ] = to_hex (uuidBytes[i]);
1040+ }
1041+ uuidStr[32 ] = 0 ;
1042+ mUuid = uuidStr;
10251043 }
1044+
1045+ // CHeck if new and old uuid differ. If either are blank, they
1046+ // differ because an error occurred.
1047+ if (oldUuid.empty () || mUuid .empty ()) return true ;
10261048 return oldUuid != mUuid ; // true if UUID in input stream differs from old UUID
10271049}
10281050
@@ -1051,12 +1073,53 @@ Archive::writeHeader(std::ostream& os, bool seekable) const
10511073 // 5) Write a flag indicating that this stream contains compressed leaf data.
10521074 // (Omitted as of version 222)
10531075
1054- // 6) Generate a new random 16-byte (128-bit) uuid and write it to the stream.
1055- std::mt19937 ran;
1056- ran.seed (std::mt19937::result_type (std::random_device ()() + std::time (nullptr )));
1057- boost::uuids::basic_random_generator<std::mt19937> gen (&ran);
1058- mUuid = gen (); // mUuid is mutable
1059- os << mUuid ;
1076+ // 6) Generate a new random 16-byte (128-bit) sequence and write it to the stream.
1077+
1078+ char uuidStr[16 *2 +4 +1 ];
1079+ auto to_hex = [](unsigned int c) -> char
1080+ {
1081+ c &= 0xf ;
1082+ if (c < 10 ) return (char )(' 0' + c);
1083+ return (char )(c - 10 + ' A' );
1084+ };
1085+
1086+ try
1087+ {
1088+ std::random_device seed;
1089+ for (int i = 0 ; i < 4 ; i++)
1090+ {
1091+ unsigned int v = seed ();
1092+ // This writes out in reverse direction of bit order, but
1093+ // as source is random we don't mind.
1094+ for (int j = 0 ; j < 8 ; j++)
1095+ {
1096+ uuidStr[i*8 +j] = to_hex (v);
1097+ v >>= 4 ;
1098+ }
1099+ }
1100+ }
1101+ catch (std::exception&)
1102+ {
1103+ // We could have failed due to running out of entropy, but hopefully
1104+ // most platforms use /dev/urandom equivalent...
1105+ // Create a blank UUID that means it should always fail comparisons.
1106+ uuidStr[0 ] = 0 ;
1107+ }
1108+ // Insert our hyphens.
1109+ for (int i = 0 ; i < 4 ; i++)
1110+ uuidStr[16 *2 +i] = ' -' ;
1111+ std::swap (uuidStr[16 *2 +0 ], uuidStr[8 +0 ]);
1112+ std::swap (uuidStr[16 *2 +1 ], uuidStr[12 +1 ]);
1113+ std::swap (uuidStr[16 *2 +2 ], uuidStr[16 +2 ]);
1114+ std::swap (uuidStr[16 *2 +3 ], uuidStr[20 +3 ]);
1115+ uuidStr[16 *2 +4 ] = 0 ;
1116+ mUuid = uuidStr; // mUuid is mutable
1117+ // We don't write a string; but instead a fixed length buffer.
1118+ // To match the old UUID, we need an extra 4 bytes for hyphens.
1119+ for (int i = 0 ; i < 16 *2 +4 ; i++)
1120+ {
1121+ os << uuidStr[i];
1122+ }
10601123}
10611124
10621125
0 commit comments