s3: fix crash if a bad listing is received - fixes #1927

Caringo Swarm is returning a listing with IsTruncated set but no
NextMarker and no Keys.  Rclone doesn't know how to continue the
listing at this point, so it returns an error rather than truncating
the listing or risking a loop.
This commit is contained in:
Nick Craig-Wood 2017-12-20 16:40:41 +00:00
parent 0d4bff8239
commit 255d3e925d

View file

@ -554,6 +554,9 @@ func (f *Fs) list(dir string, recurse bool, fn listFn) error {
}
// Use NextMarker if set, otherwise use last Key
if resp.NextMarker == nil || *resp.NextMarker == "" {
if len(resp.Contents) == 0 {
return errors.New("s3 protocol error: received listing with IsTruncated set, no NextMarker and no Contents")
}
marker = resp.Contents[len(resp.Contents)-1].Key
} else {
marker = resp.NextMarker