From b5c0384fb120e28713713ad62e4628fcd5df6a43 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 2 Dec 2020 03:07:35 +0100 Subject: [PATCH] add a test for the hashindex corruption bug, fixes #5531 for the bug, see #4829. --- src/borg/testsuite/hashindex.py | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/borg/testsuite/hashindex.py b/src/borg/testsuite/hashindex.py index fa0e3b83e..8a706ab46 100644 --- a/src/borg/testsuite/hashindex.py +++ b/src/borg/testsuite/hashindex.py @@ -510,3 +510,45 @@ class AllIndexTestCase(BaseTestCase): def test_max_load_factor(self): 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('