Test checksum types for invalid combinations (#20953)

This commit is contained in:
Klaus Post
2025-02-18 08:24:01 -08:00
committed by GitHub
parent b312f13473
commit aeabac9181
4 changed files with 20 additions and 7 deletions

View File

@@ -148,8 +148,12 @@ func (c ChecksumType) IsSet() bool {
// NewChecksumType returns a checksum type based on the algorithm string and obj type.
func NewChecksumType(alg, objType string) ChecksumType {
full := ChecksumFullObject
if objType != xhttp.AmzChecksumTypeFullObject {
switch objType {
case xhttp.AmzChecksumTypeFullObject:
case xhttp.AmzChecksumTypeComposite, "":
full = 0
default:
return ChecksumInvalid
}
switch strings.ToUpper(alg) {
@@ -567,6 +571,16 @@ func GetContentChecksum(h http.Header) (*Checksum, error) {
}
}
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
}
}