[Python-checkins] r58533 - python/trunk/Lib/bsddb/dbtables.py
gregory.p.smith
python-checkins at python.org
Thu Oct 18 10:34:20 CEST 2007
Author: gregory.p.smith
Date: Thu Oct 18 10:34:20 2007
New Revision: 58533
Modified:
python/trunk/Lib/bsddb/dbtables.py
Log:
Fix a weird bug in dbtables: if it chose a random rowid string that contained
NULL bytes it would cause the database all sorts of problems in the future
leading to very strange random failures and corrupt dbtables.bsdTableDb dbs.
Modified: python/trunk/Lib/bsddb/dbtables.py
==============================================================================
--- python/trunk/Lib/bsddb/dbtables.py (original)
+++ python/trunk/Lib/bsddb/dbtables.py Thu Oct 18 10:34:20 2007
@@ -22,7 +22,6 @@
import copy
import random
import struct
-import base64
from types import ListType, StringType
import cPickle as pickle
@@ -361,11 +360,12 @@
unique = 0
while not unique:
# Generate a random 64-bit row ID string
- # (note: this code has <64 bits of randomness
+ # (note: this code has <56 bits of randomness
# but it's plenty for our database id needs!)
+ # The | 0x01010101 is to ensure no null bytes are in the value
newid = struct.pack('ll',
- random.randint(0, 2147483647),
- random.randint(0, 2147483647))
+ random.randint(0, 2147483647) | 0x01010101,
+ random.randint(0, 2147483647) | 0x01010101)
# Guarantee uniqueness by adding this key to the database
try:
More information about the Python-checkins
mailing list