From 21e0ff97f2a6c501e5c94eac361352fd215a7107 Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx <zooko@zooko.com> Date: Fri, 2 Jan 2009 18:48:06 -0700 Subject: [PATCH] immutable: raise LayoutInvalid instead of struct.error when a share is truncated To fix this error from the Windows buildslave: [ERROR]: allmydata.test.test_immutable.Test.test_download_from_only_3_remaining_shares Traceback (most recent call last): File "C:\Documents and Settings\buildslave\windows-native-tahoe\windows\build\src\allmydata\immutable\download.py", line 135, in _bad raise NotEnoughSharesError("ran out of peers, last error was %s" % (f,)) allmydata.interfaces.NotEnoughSharesError: ran out of peers, last error was [Failure instance: Traceback: <class 'struct.error'>: unpack requires a string argument of length 4 c:\documents and settings\buildslave\windows-native-tahoe\windows\build\support\lib\site-packages\foolscap-0.3.2-py2.5.egg\foolscap\call.py:667:_done c:\documents and settings\buildslave\windows-native-tahoe\windows\build\support\lib\site-packages\foolscap-0.3.2-py2.5.egg\foolscap\call.py:53:complete c:\Python25\lib\site-packages\twisted\internet\defer.py:239:callback c:\Python25\lib\site-packages\twisted\internet\defer.py:304:_startRunCallbacks --- <exception caught here> --- c:\Python25\lib\site-packages\twisted\internet\defer.py:317:_runCallbacks C:\Documents and Settings\buildslave\windows-native-tahoe\windows\build\src\allmydata\immutable\layout.py:374:_got_length C:\Python25\lib\struct.py:87:unpack ] =============================================================================== --- src/allmydata/immutable/layout.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/allmydata/immutable/layout.py b/src/allmydata/immutable/layout.py index f1e41617..16b91c59 100644 --- a/src/allmydata/immutable/layout.py +++ b/src/allmydata/immutable/layout.py @@ -371,6 +371,8 @@ class ReadBucketProxy: offset = self._offsets['uri_extension'] d = self._read(offset, self._fieldsize) def _got_length(data): + if len(data) != 4: + raise LayoutInvalid("not enough bytes to encode URI length -- %d" % (len(data),)) length = struct.unpack(self._fieldstruct, data)[0] if length >= 2**31: # URI extension blocks are around 419 bytes long, so this must be corrupted. -- 2.45.2