From 49055658a925801bc0ddeb9b62084c7e0f33fbe6 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 8 Aug 2024 13:19:41 -0700 Subject: [PATCH] Fix missing hash in GetObjectAttributes (#20231) SHA256/SHA1 were mixed up. Simplify code as well. --- cmd/object-handlers.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 16b32bf3e..4ff2dcc0a 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -762,21 +762,14 @@ func (api objectAPIHandlers) getObjectAttributesHandler(ctx context.Context, obj if _, ok := opts.ObjectAttributes[xhttp.Checksum]; ok { chkSums := objInfo.decryptChecksums(0, r.Header) // AWS does not appear to append part number on this API call. - switch { - case chkSums["CRC32"] != "": - OA.Checksum = new(objectAttributesChecksum) - OA.Checksum.ChecksumCRC32 = strings.Split(chkSums["CRC32"], "-")[0] - case chkSums["CRC32C"] != "": - OA.Checksum = new(objectAttributesChecksum) - OA.Checksum.ChecksumCRC32C = strings.Split(chkSums["CRC32C"], "-")[0] - case chkSums["SHA256"] != "": - OA.Checksum = new(objectAttributesChecksum) - OA.Checksum.ChecksumSHA1 = strings.Split(chkSums["SHA1"], "-")[0] - case chkSums["SHA1"] != "": - OA.Checksum = new(objectAttributesChecksum) - OA.Checksum.ChecksumSHA256 = strings.Split(chkSums["SHA256"], "-")[0] + if len(chkSums) > 0 { + OA.Checksum = &objectAttributesChecksum{ + ChecksumCRC32: strings.Split(chkSums["CRC32"], "-")[0], + ChecksumCRC32C: strings.Split(chkSums["CRC32C"], "-")[0], + ChecksumSHA1: strings.Split(chkSums["SHA1"], "-")[0], + ChecksumSHA256: strings.Split(chkSums["SHA256"], "-")[0], + } } - } if _, ok := opts.ObjectAttributes[xhttp.ETag]; ok {