immutable: raise a LayoutInvalid exception instead of an AssertionError if the share is corrupted so that the sharehashtree is the wrong size

This commit is contained in:
Zooko O'Whielacronx 2009-01-05 14:01:14 -07:00
parent 98b28c1d5e
commit f4fab23bf6

View File

@ -414,7 +414,8 @@ class ReadBucketProxy:
end of the share, so we need to use the offset and read just that much."""
offset = self._offsets['share_hashes']
size = self._offsets['uri_extension'] - offset
assert size % (2+HASH_SIZE) == 0
if size % (2+HASH_SIZE) != 0:
raise LayoutInvalid("share hash tree corrupted -- should occupy a multiple of %d bytes, not %d bytes" % ((2+HASH_SIZE), size))
d = self._read(offset, size)
def _unpack_share_hashes(data):
assert len(data) == size