From a2baa978dbf0ba3dec93472b26c05b78a59e93c4 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 7 Aug 2026 13:51:16 +0100 Subject: [PATCH] pikpak: fix truncated files being created when the source ends early If the source supplied fewer bytes than its declared size, the multipart upload was completed anyway, storing a truncated file and reporting a successful upload. Check the number of bytes read from the source against the declared size before finalising and abort the upload with an error if they do not match. This was found by the new FsPutShortEOF integration test. --- backend/pikpak/multipart.go | 7 +++++++ 1 file changed, 7 insertions(+) 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)