lib/weakhash: Limit number of hits for any given weakhash

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3925
This commit is contained in:
Jakob Borg 2017-01-24 08:26:45 +00:00 committed by Audrius Butkevicius
parent de49ea594a
commit ee36e2d46d

View File

@ -16,6 +16,9 @@ import (
const (
Size = 4
// don't track more hits than this for any given weakhash
maxWeakhashFinderHits = 10
)
// Find finds all the blocks of the given size within io.Reader that matches
@ -49,7 +52,7 @@ func Find(ir io.Reader, hashesToFind []uint32, size int) (map[uint32][]int64, er
var hash uint32
for {
hash = hf.Sum32()
if existing, ok := offsets[hash]; ok {
if existing, ok := offsets[hash]; ok && len(existing) < maxWeakhashFinderHits {
offsets[hash] = append(existing, i)
}
i++