Skip to content

Commit

Permalink
Fix crashes on HEAD responses without Content-Length
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Aug 10, 2023
1 parent 9016568 commit de7f9c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/backend_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func (s *S3Backend) HeadBlob(param *HeadBlobInput) (*HeadBlobOutput, error) {
Key: &param.Key,
ETag: resp.ETag,
LastModified: resp.LastModified,
Size: uint64(*resp.ContentLength),
Size: uint64(NilInt64(resp.ContentLength)),
StorageClass: resp.StorageClass,
Metadata: metadataToLower(resp.Metadata),
},
Expand Down Expand Up @@ -907,7 +907,7 @@ func (s *S3Backend) GetBlob(param *GetBlobInput) (*GetBlobOutput, error) {
Key: &param.Key,
ETag: resp.ETag,
LastModified: resp.LastModified,
Size: uint64(*resp.ContentLength),
Size: uint64(NilInt64(resp.ContentLength)),
StorageClass: resp.StorageClass,
Metadata: metadataToLower(resp.Metadata),
},
Expand Down
8 changes: 8 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ func PTime(v time.Time) *time.Time {
return &v
}

func NilInt64(v *int64) int64 {
if v == nil {
return 0
} else {
return *v
}
}

func NilStr(v *string) string {
if v == nil {
return ""
Expand Down

0 comments on commit de7f9c5

Please sign in to comment.