From 679afe4bd81ff2773f349980f54671be19072a4d Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 2 May 2024 16:15:20 +0200 Subject: [PATCH] docker: support for requesting chunks without end offset if the specified length for the range is set to -1, then request all the data possible by using the "Range: =-" syntax for the HTTP range. Signed-off-by: Giuseppe Scrivano --- docker/docker_image_src.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docker/docker_image_src.go b/docker/docker_image_src.go index f9d4d6030f..985e5d7304 100644 --- a/docker/docker_image_src.go +++ b/docker/docker_image_src.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "math" "mime" "mime/multipart" "net/http" @@ -342,8 +343,18 @@ func (s *dockerImageSource) GetBlobAt(ctx context.Context, info types.BlobInfo, headers := make(map[string][]string) rangeVals := make([]string, 0, len(chunks)) + lastFound := false for _, c := range chunks { - rangeVals = append(rangeVals, fmt.Sprintf("%d-%d", c.Offset, c.Offset+c.Length-1)) + if lastFound { + return nil, nil, fmt.Errorf("invalid chunk requested: %v", c) + } + // If the Length is set to -1, then request anything after the specified offset. + if c.Length == math.MaxUint64 { + lastFound = true + rangeVals = append(rangeVals, fmt.Sprintf("%d-", c.Offset)) + } else { + rangeVals = append(rangeVals, fmt.Sprintf("%d-%d", c.Offset, c.Offset+c.Length-1)) + } } headers["Range"] = []string{fmt.Sprintf("bytes=%s", strings.Join(rangeVals, ","))}