From e4a41c89810f0abd84977aa72967c42b4025db82 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 15 Jul 2015 13:32:05 +0200 Subject: [PATCH] fix Traceback when running check --repair, attic issue #232 This fix is maybe not perfect yet, but maybe better than nothing. A comment by Ernest0x (see https://github.com/jborg/attic/issues/232 ): @ThomasWaldmann your patch did the job. attic check --repair did the repairing and attic delete deleted the archive. Thanks. That said, however, I am not sure if the best place to put the check is where you put it in the patch. For example, the check operation uses a custom msgpack unpacker class named "RobustUnpacker", which it does try to check for correct format (see the comment: "Abort early if the data does not look like a serialized dict"), but it seems it does not catch my case. The relevant code in 'cache.py', on the other hand, uses msgpack's Unpacker class. --- borg/archive.py | 4 ++++ borg/cache.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/borg/archive.py b/borg/archive.py index 886060d1d..a133af7bb 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -755,6 +755,10 @@ def missing_chunk_detector(chunk_id): for chunk_id, cdata in zip(items, repository.get_many(items)): unpacker.feed(self.key.decrypt(chunk_id, cdata)) for item in unpacker: + if not isinstance(item, dict): + self.report_progress('Did not get expected metadata dict - archive corrupted!', + error=True) + continue yield item repository = cache_if_remote(self.repository) diff --git a/borg/cache.py b/borg/cache.py index 1b66bc1b9..d64cdfb14 100644 --- a/borg/cache.py +++ b/borg/cache.py @@ -287,6 +287,9 @@ def fetch_and_build_idx(archive_id, repository, key, tmp_dir, tf_out): add(chunk_idx, item_id, len(data), len(chunk)) unpacker.feed(data) for item in unpacker: + if not isinstance(item, dict): + print('Error: Did not get expected metadata dict - archive corrupted!') + continue if b'chunks' in item: for chunk_id, size, csize in item[b'chunks']: add(chunk_idx, chunk_id, size, csize)