diff --git a/lib/model/model.go b/lib/model/model.go index b6ac2d689..74e598aa0 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -1524,7 +1524,7 @@ func (m *model) Request(deviceID protocol.DeviceID, folder, name string, size in } if !scanner.Validate(res.data, hash, weakHash) { - m.recheckFile(deviceID, folder, name, offset, hash) + m.recheckFile(deviceID, folder, name, offset, hash, weakHash) l.Debugf("%v REQ(in) failed validating data: %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, size) return nil, protocol.ErrNoSuchFile } @@ -1558,7 +1558,7 @@ func newLimitedRequestResponse(size int, limiters ...*byteSemaphore) *requestRes return res } -func (m *model) recheckFile(deviceID protocol.DeviceID, folder, name string, offset int64, hash []byte) { +func (m *model) recheckFile(deviceID protocol.DeviceID, folder, name string, offset int64, hash []byte, weakHash uint32) { cf, ok := m.CurrentFolderFile(folder, name) if !ok { l.Debugf("%v recheckFile: %s: %q / %q: no current file", m, deviceID, folder, name) @@ -1583,6 +1583,10 @@ func (m *model) recheckFile(deviceID protocol.DeviceID, folder, name string, off l.Debugf("%v recheckFile: %s: %q / %q i=%d: hash mismatch %x != %x", m, deviceID, folder, name, blockIndex, block.Hash, hash) return } + if weakHash != 0 && block.WeakHash != weakHash { + l.Debugf("%v recheckFile: %s: %q / %q i=%d: weak hash mismatch %v != %v", m, deviceID, folder, name, blockIndex, block.WeakHash, weakHash) + return + } // The hashes provided part of the request match what we expect to find according // to what we have in the database, yet the content we've read off the filesystem doesn't diff --git a/lib/model/model_test.go b/lib/model/model_test.go index 210416b7a..0eb19aa1c 100644 --- a/lib/model/model_test.go +++ b/lib/model/model_test.go @@ -3174,9 +3174,9 @@ func TestIssue5002(t *testing.T) { } blockSize := int32(file.BlockSize()) - m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size-int64(blockSize), []byte{1, 2, 3, 4}) - m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size, []byte{1, 2, 3, 4}) // panic - m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size+int64(blockSize), []byte{1, 2, 3, 4}) + m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size-int64(blockSize), []byte{1, 2, 3, 4}, 0) + m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size, []byte{1, 2, 3, 4}, 0) // panic + m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size+int64(blockSize), []byte{1, 2, 3, 4}, 0) } func TestParentOfUnignored(t *testing.T) {