[Python-checkins] r58536 - in python/branches/release25-maint: Lib/bsddb/dbtables.py Lib/bsddb/test/test_dbtables.py Misc/NEWS
gregory.p.smith
python-checkins at python.org
Thu Oct 18 19:15:20 CEST 2007
Author: gregory.p.smith
Date: Thu Oct 18 19:15:20 2007
New Revision: 58536
Modified:
python/branches/release25-maint/Lib/bsddb/dbtables.py
python/branches/release25-maint/Lib/bsddb/test/test_dbtables.py
python/branches/release25-maint/Misc/NEWS
Log:
Backport 58532, 58533, 58534:
- Fix bsddb.dbtables: Don't randomly corrupt newly inserted rows by
picking a rowid string with null bytes in it. Such rows could not
later be deleted, modified or individually selected. Existing
bsdTableDb databases created with such rows are out of luck.
- Use mkdtemp for the test_dbtables test database environment and
clean it up afterwards using shutil.rmtree.
Modified: python/branches/release25-maint/Lib/bsddb/dbtables.py
==============================================================================
--- python/branches/release25-maint/Lib/bsddb/dbtables.py (original)
+++ python/branches/release25-maint/Lib/bsddb/dbtables.py Thu Oct 18 19:15:20 2007
@@ -20,7 +20,7 @@
import re
import sys
import copy
-import xdrlib
+import struct
import random
from types import ListType, StringType
import cPickle as pickle
@@ -362,10 +362,11 @@
# Generate a random 64-bit row ID string
# (note: this code has <64 bits of randomness
# but it's plenty for our database id needs!)
- p = xdrlib.Packer()
- p.pack_int(int(random.random()*2147483647))
- p.pack_int(int(random.random()*2147483647))
- newid = p.get_buffer()
+ # We must ensure that no null bytes are in the id value.
+ blist = []
+ for x in xrange(_rowid_str_len):
+ blist.append(random.randint(1,255))
+ newid = struct.pack('B'*_rowid_str_len, *blist)
# Guarantee uniqueness by adding this key to the database
try:
@@ -444,7 +445,7 @@
try:
dataitem = self.db.get(
_data_key(table, column, rowid),
- txn)
+ txn=txn)
self.db.delete(
_data_key(table, column, rowid),
txn)
Modified: python/branches/release25-maint/Lib/bsddb/test/test_dbtables.py
==============================================================================
--- python/branches/release25-maint/Lib/bsddb/test/test_dbtables.py (original)
+++ python/branches/release25-maint/Lib/bsddb/test/test_dbtables.py Thu Oct 18 19:15:20 2007
@@ -21,9 +21,10 @@
# $Id$
import sys, os, re
+import shutil
+import tempfile
try:
- import cPickle
- pickle = cPickle
+ import cPickle as pickle
except ImportError:
import pickle
@@ -42,12 +43,9 @@
#----------------------------------------------------------------------
class TableDBTestCase(unittest.TestCase):
- db_home = 'db_home'
- db_name = 'test-table.db'
-
def setUp(self):
- homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
- self.homeDir = homeDir
+ homeDir = tempfile.mkdtemp()
+ self.testHomeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
self.tdb = dbtables.bsdTableDB(
@@ -55,10 +53,7 @@
def tearDown(self):
self.tdb.close()
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
+ shutil.rmtree(self.testHomeDir)
def test01(self):
tabname = "test01"
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS (original)
+++ python/branches/release25-maint/Misc/NEWS Thu Oct 18 19:15:20 2007
@@ -118,6 +118,10 @@
- Bug #1233: fix bsddb.dbshelve.DBShelf append method to work as
intended for RECNO databases.
+- Fix bsddb.dbtables: Don't randomly corrupt newly inserted rows by
+ picking a rowid string with null bytes in it. Such rows could not
+ later be deleted, modified or individually selected.
+
- Bug #1726026: Correct the field names of WIN32_FIND_DATAA and
WIN32_FIND_DATAW structures in the ctypes.wintypes module.
More information about the Python-checkins
mailing list