From f6d987d74b908c52dc16450fe1a3487db96136ff Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 27 Oct 2026 12:19:04 +0000 Subject: [PATCH] sftp: fix hashing files with a newline in their name on rsync.net Since control characters in names are no longer encoded by default, a file uploaded with a newline in its name keeps it on the server. Some restricted shells, such as the one on rsync.net, end the command at a newline even when it is quoted, so the hash command ran on a different path and failed, or could have hashed a different file. rclone now doesn't use a remote command to hash a file with a newline in its name on a unix shell, and reports the hash as unavailable instead. --- backend/sftp/sftp.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index bb1fd3b15..7512b8151 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -2458,7 +2458,14 @@ func (o *Object) Hash(ctx context.Context, r hash.Type) (string, error) { return "", hash.ErrUnsupported } - shellPathArg, err := o.fs.quoteOrEscapeShellPath(o.shellPath()) + shellPath := o.shellPath() + // Some restricted shells, such as rsync.net's, end the command at a + // newline even when it is quoted, which would hash a different file. + if o.fs.shellType == "unix" && strings.Contains(shellPath, "\n") { + fs.Debugf(o, "Can't calculate %v hash of a name containing a newline", r) + return "", nil + } + shellPathArg, err := o.fs.quoteOrEscapeShellPath(shellPath) if err != nil { return "", fmt.Errorf("failed to calculate %v hash: %w", r, err) }