lib/model: Consider weak hash on recheckFile (#6797)

This commit is contained in:
Simon Frei 2020-06-26 16:47:03 +02:00 committed by GitHub
parent e0c8865a45
commit 9c45ac381c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -1524,7 +1524,7 @@ func (m *model) Request(deviceID protocol.DeviceID, folder, name string, size in
} }
if !scanner.Validate(res.data, hash, weakHash) { 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) 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 return nil, protocol.ErrNoSuchFile
} }
@ -1558,7 +1558,7 @@ func newLimitedRequestResponse(size int, limiters ...*byteSemaphore) *requestRes
return res 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) cf, ok := m.CurrentFolderFile(folder, name)
if !ok { if !ok {
l.Debugf("%v recheckFile: %s: %q / %q: no current file", m, deviceID, folder, name) 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) l.Debugf("%v recheckFile: %s: %q / %q i=%d: hash mismatch %x != %x", m, deviceID, folder, name, blockIndex, block.Hash, hash)
return 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 // 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 // to what we have in the database, yet the content we've read off the filesystem doesn't

View File

@ -3174,9 +3174,9 @@ func TestIssue5002(t *testing.T) {
} }
blockSize := int32(file.BlockSize()) 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-int64(blockSize), []byte{1, 2, 3, 4}, 0)
m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size, []byte{1, 2, 3, 4}) // panic 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}) m.recheckFile(protocol.LocalDeviceID, "default", "foo", file.Size+int64(blockSize), []byte{1, 2, 3, 4}, 0)
} }
func TestParentOfUnignored(t *testing.T) { func TestParentOfUnignored(t *testing.T) {