lib/model: Fix block index calculation for recheckFile (fixes #5649) (#5648)

This commit is contained in:
Simon Frei
2019-04-12 15:21:07 +02:00
committed by Jakob Borg
parent 79360e2205
commit fca895a632
2 changed files with 7 additions and 6 deletions

View File

@@ -1576,7 +1576,7 @@ func (m *model) Request(deviceID protocol.DeviceID, folder, name string, size in
}
if !scanner.Validate(res.data, hash, weakHash) {
m.recheckFile(deviceID, folderFs, folder, name, int(offset)/int(size), hash)
m.recheckFile(deviceID, folderFs, folder, name, size, offset, hash)
l.Debugf("%v REQ(in) failed validating data (%v): %s: %q / %q o=%d s=%d", m, err, deviceID, folder, name, offset, size)
return nil, protocol.ErrNoSuchFile
}
@@ -1584,7 +1584,7 @@ func (m *model) Request(deviceID protocol.DeviceID, folder, name string, size in
return res, nil
}
func (m *model) recheckFile(deviceID protocol.DeviceID, folderFs fs.Filesystem, folder, name string, blockIndex int, hash []byte) {
func (m *model) recheckFile(deviceID protocol.DeviceID, folderFs fs.Filesystem, folder, name string, size int32, offset int64, hash []byte) {
cf, ok := m.CurrentFolderFile(folder, name)
if !ok {
l.Debugf("%v recheckFile: %s: %q / %q: no current file", m, deviceID, folder, name)
@@ -1596,6 +1596,7 @@ func (m *model) recheckFile(deviceID protocol.DeviceID, folderFs fs.Filesystem,
return
}
blockIndex := int(offset) / cf.BlockSize()
if blockIndex >= len(cf.Blocks) {
l.Debugf("%v recheckFile: %s: %q / %q i=%d: block index too far", m, deviceID, folder, name, blockIndex)
return