fix: reject composite CRC64NVME trailers

Apply the full-object-only rule to declared streaming checksum trailers and cover the HTTP mutation path.

Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
Feng Ruohang
2026-08-29 18:15:51 +08:00
parent d28885d0e5
commit d4c8da162b
3 changed files with 33 additions and 1 deletions
+5 -1
View File
@@ -716,7 +716,11 @@ func GetContentChecksum(h http.Header) (*Checksum, error) {
return nil, ErrInvalidChecksum
}
res.Type |= ChecksumFullObject
case xhttp.AmzChecksumTypeComposite, "":
case xhttp.AmzChecksumTypeComposite:
if res.Type.Base().Is(ChecksumCRC64NVME) {
return nil, ErrInvalidChecksum
}
case "":
default:
return nil, ErrInvalidChecksum
}
+10
View File
@@ -150,6 +150,16 @@ func TestChecksumAddToHeader(t *testing.T) {
}
}
func TestCRC64NVMECompositeTrailerIsInvalid(t *testing.T) {
h := http.Header{}
h.Set(xhttp.AmzTrailer, ChecksumCRC64NVME.Key())
h.Set(xhttp.AmzChecksumType, xhttp.AmzChecksumTypeComposite)
_, err := GetContentChecksum(h)
if !errors.Is(err, ErrInvalidChecksum) {
t.Fatalf("CRC64NVME/COMPOSITE trailer error = %v, want ErrInvalidChecksum", err)
}
}
// TestChecksumSerializeDeserialize checks AppendTo can be reversed by ChecksumFromBytes
func TestChecksumSerializeDeserialize(t *testing.T) {
myData := []byte("this-is-a-checksum-data-test")