From e2c3ba91e6b03bb1bfbec406fd4a4d7b0dc705f1 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 23 Feb 2016 20:56:58 +0100 Subject: [PATCH] Added consistency check when re-building index files. --- Duplicati/Library/Main/Operation/RepairHandler.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Duplicati/Library/Main/Operation/RepairHandler.cs b/Duplicati/Library/Main/Operation/RepairHandler.cs index 5f0f2f355..039591fd1 100644 --- a/Duplicati/Library/Main/Operation/RepairHandler.cs +++ b/Duplicati/Library/Main/Operation/RepairHandler.cs @@ -239,6 +239,8 @@ namespace Duplicati.Library.Main.Operation var w = new IndexVolumeWriter(m_options); newEntry = w; w.SetRemoteFilename(n.Name); + + var h = System.Security.Cryptography.HashAlgorithm.Create(m_options.BlockHashAlgorithm); foreach(var blockvolume in db.GetBlockVolumesFromIndexName(n.Name)) { @@ -252,7 +254,13 @@ namespace Duplicati.Library.Main.Operation if (m_options.IndexfilePolicy == Options.IndexFileStrategy.Full) foreach(var b in db.GetBlocklists(volumeid, m_options.Blocksize, hashsize)) + { + var bh = Convert.ToBase64String(h.ComputeHash(b.Item2, 0, b.Item3)); + if (bh != b.Item1) + throw new Exception(string.Format("Internal consistency check failed, generated index block has wrong hash, {0} vs {1}", bh, b.Item1)); + w.WriteBlocklist(b.Item1, b.Item2, 0, b.Item3); + } } w.Close();