mirror of
https://github.com/rclone/rclone.git
synced 2026-11-04 11:43:22 +00:00
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.
This commit is contained in:
1 parent
4b80301485
commit
f6d987d74b
1 file changed
+8
-1
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user