Thanks to visit codestin.com
Credit goes to github.com

Skip to content

huaweidrive: fix truncated files being uploaded successfully when the source ends early - #9801

Merged
ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/huaweidrive-truncated-uploads
Aug 24, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/huaweidrive-truncated-uploads

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Continues the "source ends early" sweep (#9785, #9786, #9787 and the commits it started from).

uploadSimple copied the source into the multipart request buffer with io.Copy and discarded the byte count, so a source supplying fewer bytes than its declared size was accepted by the server and reported as a success with a truncated file stored. Same shape as gofile: buffered body, no length check, silent truncation.

Count the bytes actually read with readers.NewCountingReader and fail with io.ErrUnexpectedEOF if they do not match the declared size — the same idiom as the merged box/gofile/googlephotos fixes.

uploadResume was checked and left alone: its final chunk is sent with an explicit Content-Range against the declared total, so a short source surfaces as an API error rather than a silent truncation.

Verified with go build ./..., go vet on the package, and the full unit suite matching the pre-change baseline (only the two recorded environmental failures, cmd/gitannex / cmd/serve/s3, which need git-annex and minio binaries).

… source ends early

The multipart upload copied the source into the request buffer without
checking how many bytes it had read, so a source that supplied fewer
bytes than its declared size was accepted by the server and reported as
a success with a truncated file stored.

Count the bytes actually read and fail the upload if they do not match
the declared size.

Signed-off-by: Rohit Behera <[email protected]>
@r0h1tb
r0h1tb requested a review from ncw as a code owner August 21, 2026 22:09

@CAOShurong CAOShurong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good defensive fix. Adding a byte-count verification after \io.Copy\ catches truncated input before the multipart writer closes, preventing silent data corruption. The \io.ErrUnexpectedEOF\ wrapping is appropriate — it signals the source didn't supply the declared bytes without masking the underlying copy error.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - nice fix :-)

@ncw
ncw merged commit 83b1431 into rclone:master Aug 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants