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

yandex: fix truncated files being uploaded successfully when the source ends early

Rohit Behera112869346885
diff --git a/backend/yandex/yandex.go b/backend/yandex/yandex.go
index 70aba8409..412a84da3 100644
--- a/backend/yandex/yandex.go
+++ b/backend/yandex/yandex.go
@@ -1189,6 +1189,12 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return err
}
+ // Check the source supplied the number of bytes it declared
+ // otherwise a truncated file would be stored as a good upload.
+ if size := src.Size(); size >= 0 && int64(in1.BytesRead()) != size {
+ return fmt.Errorf("expected %d bytes in input, but got %d: %w", size, in1.BytesRead(), io.ErrUnexpectedEOF)
+ }
+
// Set the modTime of the uploaded file and re-read the metadata
// so the object has the md5sum the server computed for the upload.
//