huaweidrive: fix truncated files being uploaded successfully when the source ends early - #9801
Merged
Merged
Conversation
… 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]>
CAOShurong
approved these changes
Aug 23, 2026
CAOShurong
left a comment
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues the "source ends early" sweep (#9785, #9786, #9787 and the commits it started from).
uploadSimplecopied the source into the multipart request buffer withio.Copyand 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.NewCountingReaderand fail withio.ErrUnexpectedEOFif they do not match the declared size — the same idiom as the merged box/gofile/googlephotos fixes.uploadResumewas checked and left alone: its final chunk is sent with an explicitContent-Rangeagainst the declared total, so a short source surfaces as an API error rather than a silent truncation.Verified with
go build ./...,go veton 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).