From c84ad6b7b1ffc9b6c126e73e358ee57e6706168e Mon Sep 17 00:00:00 2001 From: Martin Hostettler Date: Fri, 5 Aug 2016 22:26:59 +0200 Subject: [PATCH] Archiver.do_extract: Fix leak of downloaded chunk contents caused by preloading Include condition that path is non empty after applying strip_components into filter passed to iter_items. All filtering of files to extract must be done in the filter callable used in archive.iter_items because iter_items will preload all chunks used in items it returns. If they are not actually extracted the accumulate in the responsed dict. --- borg/archiver.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 728ece672..dc364b65b 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -371,12 +371,13 @@ class Archiver: sparse = args.sparse strip_components = args.strip_components dirs = [] - for item in archive.iter_items(lambda item: matcher.match(item[b'path']), preload=True): + filter = lambda item: matcher.match(item[b'path']) + if strip_components: + filter = lambda item: matcher.match(item[b'path']) and os.sep.join(item[b'path'].split(os.sep)[strip_components:]) + for item in archive.iter_items(filter, preload=True): orig_path = item[b'path'] if strip_components: item[b'path'] = os.sep.join(orig_path.split(os.sep)[strip_components:]) - if not item[b'path']: - continue if not args.dry_run: while dirs and not item[b'path'].startswith(dirs[-1][b'path']): dir_item = dirs.pop(-1)