From e9a95a78de7b70aa76d48650ee328c67c73a3d64 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 24 Sep 2023 16:51:58 +0100 Subject: [PATCH] s3: fix slice bounds out of range error when listing In this commit: 5f938fb9ed8aa650 s3: fix "Entry doesn't belong in directory" errors when using directory markers We checked that the remote has the prefix and then changed the remote before removing the prefix. This sometimes causes: panic: runtime error: slice bounds out of range [56:55] The fix is to do the modification of the remote after removing the prefix. See: https://forum.rclone.org/t/cryptcheck-panic-runtime-error-slice-bounds-out-of-range/41977 --- backend/s3/s3.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index db9fab8d8..87afe5e67 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -3800,11 +3800,13 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error { if remote == opt.directory { continue } - // process directory markers as directories - remote = strings.TrimRight(remote, "/") } } remote = remote[len(opt.prefix):] + if isDirectory { + // process directory markers as directories + remote = strings.TrimRight(remote, "/") + } if opt.addBucket { remote = bucket.Join(opt.bucket, remote) }