[#155] Fixed invalid max-keys handling

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-14 11:58:28 +03:00
parent 9f57756351
commit 1ecf32c302
2 changed files with 13 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package handler
import (
"encoding/xml"
"errors"
"net/http"
"strconv"
"time"
@ -119,6 +120,12 @@ func (h *handler) listObjects(w http.ResponseWriter, r *http.Request) (*listObje
zap.String("request_id", rid),
zap.Error(err))
var s3Err api.Error
if ok := errors.As(err, &s3Err); ok {
api.WriteErrorResponse(r.Context(), w, s3Err, r.URL)
return nil, nil, err
}
api.WriteErrorResponse(r.Context(), w, api.Error{
Code: api.GetAPIError(api.ErrBadRequest).Code,
Description: err.Error(),
@ -287,7 +294,7 @@ func parseListObjectArgs(r *http.Request) (*listObjectsArgs, error) {
if r.URL.Query().Get("max-keys") == "" {
res.MaxKeys = maxObjectList
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys <= 0 {
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys < 0 {
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
}
@ -384,7 +391,7 @@ func parseListObjectVersionsRequest(r *http.Request) (*layer.ListObjectVersionsP
if r.URL.Query().Get("max-keys") == "" {
res.MaxKeys = maxObjectList
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys <= 0 {
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys < 0 {
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
}

View file

@ -227,6 +227,10 @@ func (n *layer) ListObjects(ctx context.Context, p *ListObjectsParams) (*ListObj
uniqNames = make(map[string]bool)
)
if p.MaxKeys == 0 {
return &result, nil
}
if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
return nil, err
} else if ids, err = n.objectSearch(ctx, &findParams{cid: bkt.CID}); err != nil {