From ee36e2d46d3392a6a40891cce59c53556a6f16b3 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 24 Jan 2017 08:26:45 +0000 Subject: [PATCH] lib/weakhash: Limit number of hits for any given weakhash GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3925 --- lib/weakhash/weakhash.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/weakhash/weakhash.go b/lib/weakhash/weakhash.go index 1d3c0eb1..36450920 100644 --- a/lib/weakhash/weakhash.go +++ b/lib/weakhash/weakhash.go @@ -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++