From 3ca424050f993c6b1aa464f0d3cbaeb9ef33f615 Mon Sep 17 00:00:00 2001 From: Fred Akalin Date: Sat, 29 Jun 2019 11:34:54 -0700 Subject: [PATCH] Add upper bound for t in --read-data-subset=n/t (#2304) * Add upper bound for t in --read-data-subset=n/t * Add changelog entry --- changelog/unreleased/issue-2301 | 7 +++++++ cmd/restic/cmd_check.go | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 changelog/unreleased/issue-2301 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) }