diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index f2658aa718..ea307d8b0d 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -137,6 +137,10 @@ def ChunkerParams(s): raise argparse.ArgumentTypeError('min. chunk size exponent must not be less than 6 (2^6 = 64B min. chunk size)') if chunk_max > 23: raise argparse.ArgumentTypeError('max. chunk size exponent must not be more than 23 (2^23 = 8MiB max. chunk size)') + # the chunker needs the hash window plus one byte beyond the min. chunk size to fit into + # a max. chunk size sized buffer, see the assertion in Chunker.__cinit__. + if window_size + 2 ** chunk_min + 1 > 2 ** chunk_max: + raise argparse.ArgumentTypeError('required: window_size + 2^chunk_min + 1 <= 2^chunk_max') if window_size % 2 == 0: raise argparse.ArgumentTypeError("window_size must be an uneven (odd) number") return CH_BUZHASH, chunk_min, chunk_max, chunk_mask, window_size diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py index cab889194d..46975d41d3 100644 --- a/src/borg/testsuite/helpers.py +++ b/src/borg/testsuite/helpers.py @@ -391,6 +391,11 @@ def test_chunkerparams(): ChunkerParams('buzhash,5,7,6,4095') # too small min. size with pytest.raises(ArgumentTypeError): ChunkerParams('buzhash,19,24,21,4095') # too big max. size + with pytest.raises(ArgumentTypeError): + ChunkerParams('buzhash,10,12,11,4095') # window_size + 2^chunk_min + 1 > 2^chunk_max + with pytest.raises(ArgumentTypeError): + ChunkerParams('19,19,19,4095') # dito, chunk_min == chunk_max + assert ChunkerParams('10,13,11,4095') == ('buzhash', 10, 13, 11, 4095) # just fits: 4095 + 1024 + 1 <= 8192 if borg2: with pytest.raises(ArgumentTypeError): ChunkerParams('buzhash,23,19,21,4095') # violates min <= mask <= max