lib/scanner: Less strict validation (fixes #6827) (#6828)

This fixes the change in #6674 where the weak hash became a deciding
factor. Now we again just use it to accept a block, but don't take a
negative as meaning the block is bad.
This commit is contained in:
Jakob Borg 2020-07-11 14:48:45 +02:00
parent 5f40879a75
commit d57694dc04

View File

@ -108,12 +108,12 @@ func Blocks(ctx context.Context, r io.Reader, blocksize int, sizehint int64, cou
return blocks, nil return blocks, nil
} }
// Validate quickly validates buf against the cryptohash hash (if len(hash)>0) // Validate quickly validates buf against the 32-bit weakHash, if not zero,
// and the 32-bit hash weakHash (if not zero). It is satisfied if either hash // else against the cryptohash hash, if len(hash)>0. It is satisfied if
// matches, or neither is given. // either hash matches or neither hash is given.
func Validate(buf, hash []byte, weakHash uint32) bool { func Validate(buf, hash []byte, weakHash uint32) bool {
if weakHash != 0 { if weakHash != 0 && adler32.Checksum(buf) == weakHash {
return adler32.Checksum(buf) == weakHash return true
} }
if len(hash) > 0 { if len(hash) > 0 {