1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 02:08:54 +00:00

catch unpacker exceptions, resync, fixes #1351

This commit is contained in:
Thomas Waldmann 2016-07-28 22:10:29 +02:00
parent 10ecb1792d
commit edea587f35

View file

@ -754,6 +754,9 @@ def valid_msgpacked_dict(d, keys_serialized):
class RobustUnpacker: class RobustUnpacker:
"""A restartable/robust version of the streaming msgpack unpacker """A restartable/robust version of the streaming msgpack unpacker
""" """
class UnpackerCrashed(Exception):
"""raise if unpacker crashed"""
def __init__(self, validator, item_keys): def __init__(self, validator, item_keys):
super().__init__() super().__init__()
self.item_keys = [msgpack.packb(name) for name in item_keys] self.item_keys = [msgpack.packb(name) for name in item_keys]
@ -798,7 +801,10 @@ def __next__(self):
pass pass
data = data[1:] data = data[1:]
else: else:
return next(self._unpacker) try:
return next(self._unpacker)
except (TypeError, ValueError) as err:
raise self.UnpackerCrashed(str(err))
class ArchiveChecker: class ArchiveChecker:
@ -1017,6 +1023,9 @@ def valid_item(obj):
yield item yield item
else: else:
report('Did not get expected metadata dict when unpacking item metadata', chunk_id, i) report('Did not get expected metadata dict when unpacking item metadata', chunk_id, i)
except RobustUnpacker.UnpackerCrashed as err:
report('Unpacker crashed while unpacking item metadata, trying to resync...', chunk_id, i)
unpacker.resync()
except Exception: except Exception:
report('Exception while unpacking item metadata', chunk_id, i) report('Exception while unpacking item metadata', chunk_id, i)
raise raise