Skip to content

Commit

Permalink
blob/azureblob: Do not panic if Content-Length and Content-Range are …
Browse files Browse the repository at this point in the history
…missing (#3445)

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez committed Jun 13, 2024
1 parent ba58ec7 commit e0142cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions blob/azureblob/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length
}
attrs := driver.ReaderAttributes{
ContentType: to.String(blobDownloadResponse.ContentType),
Size: getSize(*blobDownloadResponse.ContentLength, to.String(blobDownloadResponse.ContentRange)),
Size: getSize(blobDownloadResponse.ContentLength, to.String(blobDownloadResponse.ContentRange)),
ModTime: *blobDownloadResponse.LastModified,
}
var body io.ReadCloser
Expand All @@ -584,11 +584,14 @@ func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length
}, nil
}

func getSize(contentLength int64, contentRange string) int64 {
func getSize(contentLength *int64, contentRange string) int64 {
var size int64
// Default size to ContentLength, but that's incorrect for partial-length reads,
// where ContentLength refers to the size of the returned Body, not the entire
// size of the blob. ContentRange has the full size.
size := contentLength
if contentLength != nil {
size = *contentLength
}
if contentRange != "" {
// Sample: bytes 10-14/27 (where 27 is the full size).
parts := strings.Split(contentRange, "/")
Expand Down

0 comments on commit e0142cf

Please sign in to comment.