From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Mon, 5 Jan 2009 21:01:14 +0000 (-0700)
Subject: immutable: raise a LayoutInvalid exception instead of an AssertionError if the share... 
X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/somewhere?a=commitdiff_plain;h=f4fab23bf63c4c5a786048561a1232f7f4521db7;p=tahoe-lafs%2Ftahoe-lafs.git

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

diff --git a/src/allmydata/immutable/layout.py b/src/allmydata/immutable/layout.py
index 07d1131f..8ab6e1db 100644
--- a/src/allmydata/immutable/layout.py
+++ b/src/allmydata/immutable/layout.py
@@ -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