Commit b6ac347a authored by Christian Robottom's avatar Christian Robottom

Implement check for invalid oids when the FileStorage's _index member

is accessed. This improves some odd unsliceable object TypeErrors which
popped up from inside fsIndex.
parent 41713b26
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
# may have a back pointer to a version record or to a non-version # may have a back pointer to a version record or to a non-version
# record. # record.
# #
__version__='$Revision: 1.132 $'[11:-2] __version__='$Revision: 1.133 $'[11:-2]
import base64 import base64
from cPickle import Pickler, Unpickler, loads from cPickle import Pickler, Unpickler, loads
...@@ -595,6 +595,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -595,6 +595,8 @@ class FileStorage(BaseStorage.BaseStorage,
pos=_index[oid] pos=_index[oid]
except KeyError: except KeyError:
raise POSKeyError(oid) raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
file.seek(pos) file.seek(pos)
read=file.read read=file.read
h=read(DATA_HDR_LEN) h=read(DATA_HDR_LEN)
...@@ -616,6 +618,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -616,6 +618,8 @@ class FileStorage(BaseStorage.BaseStorage,
pos = _index[oid] pos = _index[oid]
except KeyError: except KeyError:
raise POSKeyError(oid) raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
file.seek(pos) file.seek(pos)
read = file.read read = file.read
h = read(DATA_HDR_LEN) h = read(DATA_HDR_LEN)
...@@ -655,6 +659,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -655,6 +659,8 @@ class FileStorage(BaseStorage.BaseStorage,
pos = self._index[oid] pos = self._index[oid]
except KeyError: except KeyError:
raise POSKeyError(oid) raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
while 1: while 1:
seek(pos) seek(pos)
h=read(DATA_HDR_LEN) h=read(DATA_HDR_LEN)
...@@ -686,6 +692,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -686,6 +692,8 @@ class FileStorage(BaseStorage.BaseStorage,
pos = self._index[oid] pos = self._index[oid]
except KeyError: except KeyError:
raise POSKeyError(oid) raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
file=self._file file=self._file
file.seek(pos) file.seek(pos)
doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", file.read(34)) doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", file.read(34))
...@@ -1082,7 +1090,12 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1082,7 +1090,12 @@ class FileStorage(BaseStorage.BaseStorage,
def getSerial(self, oid): def getSerial(self, oid):
self._lock_acquire() self._lock_acquire()
try: try:
return self._getSerial(oid, self._index[oid]) try:
return self._getSerial(oid, self._index[oid])
except KeyError:
raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
finally: finally:
self._lock_release() self._lock_release()
...@@ -1370,7 +1383,12 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1370,7 +1383,12 @@ class FileStorage(BaseStorage.BaseStorage,
file=self._file file=self._file
seek=file.seek seek=file.seek
read=file.read read=file.read
pos=self._index[oid] try:
pos=self._index[oid]
except KeyError:
raise POSKeyError(oid)
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
wantver=version wantver=version
while 1: while 1:
...@@ -1503,6 +1521,8 @@ class FileStorage(BaseStorage.BaseStorage, ...@@ -1503,6 +1521,8 @@ class FileStorage(BaseStorage.BaseStorage,
pos = self._index[oid] pos = self._index[oid]
except KeyError: except KeyError:
return None return None
except TypeError:
raise TypeError, 'invalid oid %r' % (oid,)
self._file.seek(pos) self._file.seek(pos)
# first 8 bytes are oid, second 8 bytes are serialno # first 8 bytes are oid, second 8 bytes are serialno
h = self._file.read(16) h = self._file.read(16)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment