Commit a10190ff authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Sebastien Robin

Prevent using negative offsets.

parent 8cd57536
...@@ -9,6 +9,8 @@ class PersistentString(Persistent): ...@@ -9,6 +9,8 @@ class PersistentString(Persistent):
def __str__(self): def __str__(self):
return self.value return self.value
negative_offset_error = ValueError('Negative offset')
class BTreeData(Persistent): class BTreeData(Persistent):
""" """
In-ZODB (non-BLOB) storage of arbitrary binary data. In-ZODB (non-BLOB) storage of arbitrary binary data.
...@@ -49,6 +51,8 @@ class BTreeData(Persistent): ...@@ -49,6 +51,8 @@ class BTreeData(Persistent):
Offset of first data byte. Offset of first data byte.
""" """
# TODO: auto-aggregation of continuous keys when overwriting # TODO: auto-aggregation of continuous keys when overwriting
if offset < 0:
raise negative_offset_error
tree = self._tree tree = self._tree
key = offset key = offset
try: try:
...@@ -97,6 +101,8 @@ class BTreeData(Persistent): ...@@ -97,6 +101,8 @@ class BTreeData(Persistent):
Returns string of read data. Returns string of read data.
""" """
if offset < 0:
raise negative_offset_error
tree = self._tree tree = self._tree
try: try:
key = tree.maxKey(offset) key = tree.maxKey(offset)
...@@ -140,6 +146,8 @@ class BTreeData(Persistent): ...@@ -140,6 +146,8 @@ class BTreeData(Persistent):
offset (int) offset (int)
Offet of the first byte to discard. Offet of the first byte to discard.
""" """
if offset < 0:
raise negative_offset_error
tree = self._tree tree = self._tree
try: try:
key = tree.maxKey(offset) key = tree.maxKey(offset)
......
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