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

pikpak: fix truncated files being created when the source ends early

Nick Craig-Wooda2baa978dbf0
diff --git a/backend/pikpak/multipart.go b/backend/pikpak/multipart.go
index 85dc8f2d5..ad453b00a 100644
--- a/backend/pikpak/multipart.go
+++ b/backend/pikpak/multipart.go
@@ -128,6 +128,13 @@ func (w *pikpakChunkWriter) Upload(ctx context.Context) (err error) {
return err
}
+ // Check the source supplied the number of bytes it declared before
+ // finalising, otherwise a truncated file would be stored as a good
+ // upload. Returning an error here aborts the upload.
+ if size >= 0 && off != size {
+ return fmt.Errorf("multipart upload: expected %d bytes in input, but got %d: %w", size, off, io.ErrUnexpectedEOF)
+ }
+
err = w.Close(ctx)
if err != nil {
return fmt.Errorf("multipart upload: failed to finalise: %w", err)