canonicalize ETag correctly (#7442)

Fixes #7441 
Trim extra quotes prefixing/suffixing ETag in
CompleteMultipartUpload request.
master
poornas 6 years ago committed by kannappanr
parent 619611933a
commit 023866642c
  1. 5
      cmd/fs-v1-multipart.go
  2. 3
      cmd/object-api-multipart_test.go
  3. 2
      cmd/object-api-utils.go
  4. 9
      cmd/object-handlers-common.go
  5. 53
      cmd/object-handlers-common_test.go
  6. 2
      cmd/xl-v1-multipart.go

@ -524,6 +524,11 @@ func (fs *FSObjects) CompleteMultipartUpload(ctx context.Context, bucket string,
return oi, err return oi, err
} }
// ensure that part ETag is canonicalized to strip off extraneous quotes
for i := range parts {
parts[i].ETag = canonicalizeETag(parts[i].ETag)
}
// Save consolidated actual size. // Save consolidated actual size.
var objectActualSize int64 var objectActualSize int64
// Validate all parts and then commit to disk. // Validate all parts and then commit to disk.

@ -1796,6 +1796,7 @@ func testObjectCompleteMultipartUpload(obj ObjectLayer, instanceType string, t T
// Part with size larger than 5Mb. // Part with size larger than 5Mb.
{bucketNames[0], objectNames[0], uploadIDs[0], 5, string(validPart), validPartMD5, int64(len(string(validPart)))}, {bucketNames[0], objectNames[0], uploadIDs[0], 5, string(validPart), validPartMD5, int64(len(string(validPart)))},
{bucketNames[0], objectNames[0], uploadIDs[0], 6, string(validPart), validPartMD5, int64(len(string(validPart)))}, {bucketNames[0], objectNames[0], uploadIDs[0], 6, string(validPart), validPartMD5, int64(len(string(validPart)))},
{bucketNames[0], objectNames[0], uploadIDs[0], 7, string(validPart), validPartMD5, int64(len(string(validPart)))},
} }
sha256sum := "" sha256sum := ""
var opts ObjectOptions var opts ObjectOptions
@ -1837,7 +1838,7 @@ func testObjectCompleteMultipartUpload(obj ObjectLayer, instanceType string, t T
// Part size greater than 5MB. // Part size greater than 5MB.
{ {
[]CompletePart{ []CompletePart{
{ETag: validPartMD5, PartNumber: 5}, {ETag: fmt.Sprintf("\"\"\"\"\"%s\"\"\"", validPartMD5), PartNumber: 5},
}, },
}, },
// inputParts - 4. // inputParts - 4.

@ -193,7 +193,7 @@ func mustGetUUID() string {
func getCompleteMultipartMD5(ctx context.Context, parts []CompletePart) (string, error) { func getCompleteMultipartMD5(ctx context.Context, parts []CompletePart) (string, error) {
var finalMD5Bytes []byte var finalMD5Bytes []byte
for _, part := range parts { for _, part := range parts {
md5Bytes, err := hex.DecodeString(part.ETag) md5Bytes, err := hex.DecodeString(canonicalizeETag(part.ETag))
if err != nil { if err != nil {
logger.LogIf(ctx, err) logger.LogIf(ctx, err)
return "", err return "", err

@ -19,7 +19,7 @@ package cmd
import ( import (
"context" "context"
"net/http" "net/http"
"strings" "regexp"
"time" "time"
"github.com/minio/minio/cmd/crypto" "github.com/minio/minio/cmd/crypto"
@ -27,6 +27,10 @@ import (
"github.com/minio/minio/pkg/handlers" "github.com/minio/minio/pkg/handlers"
) )
var (
etagRegex = regexp.MustCompile("\"*?([^\"]*?)\"*?$")
)
// Validates the preconditions for CopyObjectPart, returns true if CopyObjectPart // Validates the preconditions for CopyObjectPart, returns true if CopyObjectPart
// operation should not proceed. Preconditions supported are: // operation should not proceed. Preconditions supported are:
// x-amz-copy-source-if-modified-since // x-amz-copy-source-if-modified-since
@ -230,8 +234,7 @@ func ifModifiedSince(objTime time.Time, givenTime time.Time) bool {
// canonicalizeETag returns ETag with leading and trailing double-quotes removed, // canonicalizeETag returns ETag with leading and trailing double-quotes removed,
// if any present // if any present
func canonicalizeETag(etag string) string { func canonicalizeETag(etag string) string {
canonicalETag := strings.TrimPrefix(etag, "\"") return etagRegex.ReplaceAllString(etag, "$1")
return strings.TrimSuffix(canonicalETag, "\"")
} }
// isETagEqual return true if the canonical representations of two ETag strings // isETagEqual return true if the canonical representations of two ETag strings

@ -0,0 +1,53 @@
/*
* Minio Cloud Storage, (C) 2019 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"testing"
)
// Tests - canonicalizeETag()
func TestCanonicalizeETag(t *testing.T) {
testCases := []struct {
etag string
canonicalizedETag string
}{
{
etag: "\"\"\"",
canonicalizedETag: "",
},
{
etag: "\"\"\"abc\"",
canonicalizedETag: "abc",
},
{
etag: "abcd",
canonicalizedETag: "abcd",
},
{
etag: "abcd\"\"",
canonicalizedETag: "abcd",
},
}
for _, test := range testCases {
etag := canonicalizeETag(test.etag)
if test.canonicalizedETag != etag {
t.Fatalf("Expected %s , got %s", test.canonicalizedETag, etag)
}
}
}

@ -675,6 +675,8 @@ func (xl xlObjects) CompleteMultipartUpload(ctx context.Context, bucket string,
// Validate each part and then commit to disk. // Validate each part and then commit to disk.
for i, part := range parts { for i, part := range parts {
// ensure that part ETag is canonicalized to strip off extraneous quotes
part.ETag = canonicalizeETag(part.ETag)
partIdx := objectPartIndex(currentXLMeta.Parts, part.PartNumber) partIdx := objectPartIndex(currentXLMeta.Parts, part.PartNumber)
// All parts should have same part number. // All parts should have same part number.
if partIdx == -1 { if partIdx == -1 {

Loading…
Cancel
Save