mirror of
https://github.com/minio/minio.git
synced 2025-04-27 05:15:01 -04:00
Test checksum types for invalid combinations (#20953)
This commit is contained in:
parent
b312f13473
commit
aeabac9181
@ -2254,6 +2254,8 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) {
|
|||||||
apiErr = ErrServerNotInitialized
|
apiErr = ErrServerNotInitialized
|
||||||
case errBucketMetadataNotInitialized:
|
case errBucketMetadataNotInitialized:
|
||||||
apiErr = ErrBucketMetadataNotInitialized
|
apiErr = ErrBucketMetadataNotInitialized
|
||||||
|
case hash.ErrInvalidChecksum:
|
||||||
|
apiErr = ErrInvalidChecksum
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compression errors
|
// Compression errors
|
||||||
|
@ -467,13 +467,10 @@ func completeMultipartOpts(ctx context.Context, r *http.Request, bucket, object
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.WantChecksum, err = hash.GetContentChecksum(r.Header)
|
opts.WantChecksum, err = hash.GetContentChecksum(r.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return opts, InvalidArgument{
|
return opts, err
|
||||||
Bucket: bucket,
|
|
||||||
Object: object,
|
|
||||||
Err: fmt.Errorf("invalid/unknown checksum sent: %v", err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
opts.MTime = mtime
|
opts.MTime = mtime
|
||||||
opts.UserDefined = make(map[string]string)
|
opts.UserDefined = make(map[string]string)
|
||||||
|
@ -216,7 +216,7 @@ func (api objectAPIHandlers) NewMultipartUploadHandler(w http.ResponseWriter, r
|
|||||||
|
|
||||||
checksumType := hash.NewChecksumHeader(r.Header)
|
checksumType := hash.NewChecksumHeader(r.Header)
|
||||||
if checksumType.Is(hash.ChecksumInvalid) {
|
if checksumType.Is(hash.ChecksumInvalid) {
|
||||||
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidRequestParameter), r.URL)
|
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrInvalidChecksum), r.URL)
|
||||||
return
|
return
|
||||||
} else if checksumType.IsSet() && !checksumType.Is(hash.ChecksumTrailing) {
|
} else if checksumType.IsSet() && !checksumType.Is(hash.ChecksumTrailing) {
|
||||||
opts.WantChecksum = &hash.Checksum{Type: checksumType}
|
opts.WantChecksum = &hash.Checksum{Type: checksumType}
|
||||||
|
@ -148,8 +148,12 @@ func (c ChecksumType) IsSet() bool {
|
|||||||
// NewChecksumType returns a checksum type based on the algorithm string and obj type.
|
// NewChecksumType returns a checksum type based on the algorithm string and obj type.
|
||||||
func NewChecksumType(alg, objType string) ChecksumType {
|
func NewChecksumType(alg, objType string) ChecksumType {
|
||||||
full := ChecksumFullObject
|
full := ChecksumFullObject
|
||||||
if objType != xhttp.AmzChecksumTypeFullObject {
|
switch objType {
|
||||||
|
case xhttp.AmzChecksumTypeFullObject:
|
||||||
|
case xhttp.AmzChecksumTypeComposite, "":
|
||||||
full = 0
|
full = 0
|
||||||
|
default:
|
||||||
|
return ChecksumInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
switch strings.ToUpper(alg) {
|
switch strings.ToUpper(alg) {
|
||||||
@ -567,6 +571,16 @@ func GetContentChecksum(h http.Header) (*Checksum, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
switch h.Get(xhttp.AmzChecksumType) {
|
||||||
|
case xhttp.AmzChecksumTypeFullObject:
|
||||||
|
if !res.Type.CanMerge() {
|
||||||
|
return nil, ErrInvalidChecksum
|
||||||
|
}
|
||||||
|
res.Type |= ChecksumFullObject
|
||||||
|
case xhttp.AmzChecksumTypeComposite, "":
|
||||||
|
default:
|
||||||
|
return nil, ErrInvalidChecksum
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user