diff --git a/changelog/unreleased/issue-2301 b/changelog/unreleased/issue-2301 new file mode 100644 index 000000000..d596dbf69 --- /dev/null +++ b/changelog/unreleased/issue-2301 @@ -0,0 +1,7 @@ +Bugfix: Add upper bound for t in --read-data-subset=n/t + +256 is the effective maximum for t, but restic would allow larger +values, leading to strange behavior. + +https://github.com/restic/restic/issues/2301 +https://github.com/restic/restic/pull/2304 diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index bee7eae54..d0735d07e 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -67,11 +67,17 @@ func checkFlags(opts CheckOptions) error { if dataSubset[0] == 0 || dataSubset[1] == 0 || dataSubset[0] > dataSubset[1] { return errors.Fatalf("check flag --read-data-subset=n/t values must be positive integers, and n <= t, e.g. --read-data-subset=1/2") } + if dataSubset[1] > totalBucketsMax { + return errors.Fatalf("check flag --read-data-subset=n/t t must be at most %d", totalBucketsMax) + } } return nil } +// See doReadData in runCheck below for why this is 256. +const totalBucketsMax = 256 + // stringToIntSlice converts string to []uint, using '/' as element separator func stringToIntSlice(param string) (split []uint, err error) { if param == "" { @@ -257,6 +263,8 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { doReadData := func(bucket, totalBuckets uint) { packs := restic.IDSet{} for pack := range chkr.GetPacks() { + // If we ever check more than the first byte + // of pack, update totalBucketsMax. if (uint(pack[0]) % totalBuckets) == (bucket - 1) { packs.Insert(pack) }