From 6d31f25aa4057cde54cdf49c7404a7cc502b5577 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 2 Dec 2020 03:24:04 +0100 Subject: [PATCH] add a test for the hashindex corruption bug, fixes #5531 for the bug, see #4829. --- borg/testsuite/hashindex.py | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/borg/testsuite/hashindex.py b/borg/testsuite/hashindex.py index 5fd9e304..78d166a9 100644 --- a/borg/testsuite/hashindex.py +++ b/borg/testsuite/hashindex.py @@ -284,3 +284,45 @@ def test_nsindex_segment_limit(): def test_max_load_factor(): assert NSIndex.MAX_LOAD_FACTOR < 1.0 assert ChunkIndex.MAX_LOAD_FACTOR < 1.0 + + +class IndexCorruptionTestCase(BaseTestCase): + def test_bug_4829(self): + + from struct import pack + + def HH(x, y): + # make some 32byte long thing that depends on x and y. + # same x will mean a collision in the hashtable as bucket index is computed from + # first 4 bytes. giving a specific x targets bucket index x. + # y is to create different keys and does not go into the bucket index calculation. + # so, same x + different y --> collision + return pack('