Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

copy: fix nil pointer dereference when corrupted on transfer with nil dst

nielashe053c8a1c03e
diff --git a/backend/local/local_internal_test.go b/backend/local/local_internal_test.go
index 06e47bed2..68ca696a6 100644
--- a/backend/local/local_internal_test.go
+++ b/backend/local/local_internal_test.go
@@ -76,6 +76,23 @@ func TestUpdatingCheck(t *testing.T) {
}
+// Test corrupted on transfer
+// should error due to size/hash mismatch
+func TestVerifyCopy(t *testing.T) {
+ r := fstest.NewRun(t)
+ filePath := "sub dir/local test"
+ r.WriteFile(filePath, "some content", time.Now())
+ src, err := r.Flocal.NewObject(context.Background(), filePath)
+ require.NoError(t, err)
+ src.(*Object).fs.opt.NoCheckUpdated = true
+
+ for i := 0; i < 100; i++ {
+ go r.WriteFile(src.Remote(), fmt.Sprintf("some new content %d", i), src.ModTime(context.Background()))
+ }
+ _, err = operations.Copy(context.Background(), r.Fremote, nil, filePath+"2", src)
+ assert.Error(t, err)
+}
+
func TestSymlink(t *testing.T) {
ctx := context.Background()
r := fstest.NewRun(t)
diff --git a/fs/operations/copy.go b/fs/operations/copy.go
index 45fb3f64a..41605e901 100644
--- a/fs/operations/copy.go
+++ b/fs/operations/copy.go
@@ -266,14 +266,14 @@ func (c *copy) manualCopy(ctx context.Context) (actionTaken string, newDst fs.Ob
func (c *copy) verify(ctx context.Context, newDst fs.Object) (err error) {
// Verify sizes are the same after transfer
if sizeDiffers(ctx, c.src, newDst) {
- return fmt.Errorf("corrupted on transfer: sizes differ src(%s) %d vs dst(%s) %d", c.src.Fs(), c.src.Size(), c.dst.Fs(), c.dst.Size())
+ return fmt.Errorf("corrupted on transfer: sizes differ src(%s) %d vs dst(%s) %d", c.src.Fs(), c.src.Size(), newDst.Fs(), newDst.Size())
}
// Verify hashes are the same after transfer - ignoring blank hashes
if c.hashType != hash.None {
// checkHashes has logs and counts errors
equal, _, srcSum, dstSum, _ := checkHashes(ctx, c.src, newDst, c.hashType)
if !equal {
- return fmt.Errorf("corrupted on transfer: %v hashes differ src(%s) %q vs dst(%s) %q", c.hashType, c.src.Fs(), srcSum, c.dst.Fs(), dstSum)
+ return fmt.Errorf("corrupted on transfer: %v hashes differ src(%s) %q vs dst(%s) %q", c.hashType, c.src.Fs(), srcSum, newDst.Fs(), dstSum)
}
}
return nil