Skip to content

Commit ec70cd9

Browse files
Manually compute PutObject crc32 sum (#1738)
1 parent 30ced7c commit ec70cd9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

linode/helper/objects.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func S3Connection(ctx context.Context, endpoint, accessKey, secretKey string) (*
5151
}
5252
s3Client := s3.NewFromConfig(awsSDKConfig, func(opts *s3.Options) {
5353
opts.BaseEndpoint = aws.String("https://" + endpoint)
54+
55+
opts.DisableLogOutputChecksumValidationSkipped = true
5456
})
5557
return s3Client, nil
5658
}

linode/obj/helpers.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package obj
22

33
import (
44
"context"
5+
"encoding/base64"
56
"fmt"
7+
"hash/crc32"
8+
"io"
69
"regexp"
710
"slices"
811
"strings"
@@ -340,11 +343,33 @@ func fwPutObject(
340343
}
341344
defer body.Close()
342345

346+
sumHandler := crc32.NewIEEE()
347+
if _, err := io.Copy(sumHandler, body); err != nil {
348+
diags.AddError(
349+
"Failed to calculate object body CRC32 sum",
350+
err.Error(),
351+
)
352+
return
353+
}
354+
355+
encodedSum := base64.StdEncoding.EncodeToString(sumHandler.Sum(nil))
356+
357+
// Seek the beginning of the body for uploading
358+
if _, err := body.Seek(0, 0); err != nil {
359+
diags.AddError(
360+
"Failed to seek beginning of object body",
361+
err.Error(),
362+
)
363+
return
364+
}
365+
343366
putInput := &s3.PutObjectInput{
344367
Body: body,
345368
Bucket: data.Bucket.ValueStringPointer(),
346369
Key: data.Key.ValueStringPointer(),
347370

371+
ChecksumCRC32: &encodedSum,
372+
348373
ACL: s3types.ObjectCannedACL(data.ACL.ValueString()),
349374
CacheControl: data.CacheControl.ValueStringPointer(),
350375
ContentDisposition: data.ContentDisposition.ValueStringPointer(),

0 commit comments

Comments
 (0)