From 62f2422f6aeccce7587338daa900227c40c863a4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 14 Feb 2019 11:38:11 +0100 Subject: [PATCH] backup/chunk_store: verify chunk file names get_chunk_iterator() should skip over files which aren't an actual chunk Signed-off-by: Wolfgang Bumiller --- src/backup/chunk_store.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backup/chunk_store.rs b/src/backup/chunk_store.rs index bc9ba768..e472ed3d 100644 --- a/src/backup/chunk_store.rs +++ b/src/backup/chunk_store.rs @@ -229,7 +229,24 @@ impl ChunkStore { Ok(iter) => Some(iter), } }) - .flatten()) + .flatten() + .filter(|entry| { + // Check that the file name is actually a hash! (64 hex digits) + let entry = match entry { + Err(_) => return true, // pass errors onwards + Ok(ref entry) => entry, + }; + let bytes = entry.file_name().to_bytes(); + if bytes.len() != 64 { + return false; + } + for b in bytes { + if !b.is_ascii_hexdigit() { + return false; + } + } + true + })) } pub fn sweep_unused_chunks(&self, status: &mut GarbageCollectionStatus) -> Result<(), Error> {