From 1e117b780a1e1c0c084f6791cbf759edc52b0753 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 12 Oct 2021 09:24:19 -0700 Subject: [PATCH] fix: validate exclusivity with partNumber regardless of valid Range (#13418) To mimic an exact AWS S3 behavior this fix is needed. --- cmd/object-handlers.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 7fbbfd0e1..67df89ecd 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -376,6 +376,12 @@ func (api objectAPIHandlers) getObjectHandler(ctx context.Context, objectAPI Obj var rangeErr error rangeHeader := r.Header.Get(xhttp.Range) if rangeHeader != "" { + // Both 'Range' and 'partNumber' cannot be specified at the same time + if opts.PartNumber > 0 { + writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidRangePartNumber), r.URL) + return + } + rs, rangeErr = parseRequestRangeSpec(rangeHeader) // Handle only errInvalidRange. Ignore other // parse error and treat it as regular Get @@ -389,12 +395,6 @@ func (api objectAPIHandlers) getObjectHandler(ctx context.Context, objectAPI Obj } } - // Both 'bytes' and 'partNumber' cannot be specified at the same time - if rs != nil && opts.PartNumber > 0 { - writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidRangePartNumber), r.URL) - return - } - // Validate pre-conditions if any. opts.CheckPrecondFn = func(oi ObjectInfo) bool { if objectAPI.IsEncryptionSupported() { @@ -703,6 +703,12 @@ func (api objectAPIHandlers) headObjectHandler(ctx context.Context, objectAPI Ob var rs *HTTPRangeSpec rangeHeader := r.Header.Get(xhttp.Range) if rangeHeader != "" { + // Both 'Range' and 'partNumber' cannot be specified at the same time + if opts.PartNumber > 0 { + writeErrorResponseHeadersOnly(w, errorCodes.ToAPIErr(ErrInvalidRangePartNumber)) + return + } + if rs, err = parseRequestRangeSpec(rangeHeader); err != nil { // Handle only errInvalidRange. Ignore other // parse error and treat it as regular Get @@ -716,12 +722,6 @@ func (api objectAPIHandlers) headObjectHandler(ctx context.Context, objectAPI Ob } } - // Both 'bytes' and 'partNumber' cannot be specified at the same time - if rs != nil && opts.PartNumber > 0 { - writeErrorResponseHeadersOnly(w, errorCodes.ToAPIErr(ErrInvalidRangePartNumber)) - return - } - // Set encryption response headers if objectAPI.IsEncryptionSupported() { switch kind, _ := crypto.IsEncrypted(objInfo.UserDefined); kind {