From e99be0205556700bd26e276e911a26dec0c0ac76 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 24 Feb 2018 08:33:54 +0100 Subject: [PATCH] lib/model: Don't panic if block size in index is larger than protocol block size This doesn't happen today, but it might in the future if the block size were increased or made variable and we were talking to a client from the future. --- lib/model/rwfolder.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/model/rwfolder.go b/lib/model/rwfolder.go index 2a04cc27..07dfcc83 100644 --- a/lib/model/rwfolder.go +++ b/lib/model/rwfolder.go @@ -1260,7 +1260,11 @@ func (f *sendReceiveFolder) copierRoutine(in <-chan copyBlocksState, pullChan ch continue } - buf = buf[:int(block.Size)] + if s := int(block.Size); s > cap(buf) { + buf = make([]byte, s) + } else { + buf = buf[:s] + } found, err := weakHashFinder.Iterate(block.WeakHash, buf, func(offset int64) bool { if _, err := verifyBuffer(buf, block); err != nil {