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

Skip to content

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

Merged
ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/yandex-truncated-upload
Aug 21, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
r0h1tb:fix/yandex-truncated-upload

Conversation

@r0h1tb

@r0h1tb r0h1tb commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Continues the "source ends early" sweep (5d05754 sia, a2baa97 pikpak, e1bf940 filelu,
7357fb8 internetarchive, 884b28c azurefiles, 18fa445 compress).

Problem

(*Object).Update already wraps the source in a counting reader:

in1 := readers.NewCountingReader(in)
...
err = o.upload(ctx, in1, true, fs.MimeType(ctx, src), options...)

but BytesRead() is never called anywhere in the package, so the count is discarded.

The upload itself is a PUT with Body: in1 and no ContentLength, so it is chunked: a
source that stops short just sends a shorter body, the server accepts it, and Update
carries on to set the modtime and returns success with a truncated file stored.

Fix

Compare the bytes actually read against the declared size after the upload, using the
counter that is already there. No new imports.

Verification

go build ./..., go test ./backend/yandex/... and golangci-lint run ./backend/yandex/...
(0 issues) all pass. RCLONE_CONFIG=/notfound go test ./... is unchanged from master:
cmd/gitannex and cmd/serve/s3 fail identically before and after this commit on my
machine (no git-annex or minio binary locally). No Yandex remote here, so the backend
integration tests have not been run against a real remote.

Companion to #9785 (box), same class.

…ce ends early

Update already wrapped the source in a counting reader but never looked at the
count, so a source that supplied fewer bytes than its declared size was
uploaded as a chunked request, accepted by the server and reported as a
success with a truncated file stored.

Compare the bytes actually read against the declared size.

@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.

Nice fix - thank you.

The FsPutShortEOF integration test against a real Yandex remote and the fix behaves exactly as intended: the upload now fails with "expected 10240 bytes in input, but got 5120: unexpected EOF" instead of succeeding

@ncw
ncw merged commit 1128693 into rclone:master Aug 21, 2026
8 of 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.

2 participants