Skip to content

Commit

Permalink
registry/handlers remove content range validiation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhij committed Aug 15, 2023
1 parent e5d5810 commit 4741041
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 61 deletions.
38 changes: 2 additions & 36 deletions registry/handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,32 +699,6 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {

finishUpload(t, env.builder, imageName, uploadURLBase, dgst)

// -----------------------------------------
// Do layer push with invalid content range
layerFile.Seek(0, io.SeekStart)
uploadURLBase, _ = startPushLayer(t, env, imageName)
sizeInvalid := chunkOptions{
contentRange: "0-20",
}
resp, err = doPushChunk(t, uploadURLBase, layerFile, sizeInvalid)
if err != nil {
t.Fatalf("unexpected error doing push layer request: %v", err)
}
defer resp.Body.Close()
checkResponse(t, "putting size invalid chunk", resp, http.StatusBadRequest)

layerFile.Seek(0, io.SeekStart)
uploadURLBase, _ = startPushLayer(t, env, imageName)
outOfOrder := chunkOptions{
contentRange: "3-22",
}
resp, err = doPushChunk(t, uploadURLBase, layerFile, outOfOrder)
if err != nil {
t.Fatalf("unexpected error doing push layer request: %v", err)
}
defer resp.Body.Close()
checkResponse(t, "putting range out of order chunk", resp, http.StatusRequestedRangeNotSatisfiable)

// ------------------------
// Use a head request to see if the layer exists.
resp, err = http.Head(layerURL)
Expand Down Expand Up @@ -2536,12 +2510,7 @@ func finishUpload(t *testing.T, ub *v2.URLBuilder, name reference.Named, uploadU
return resp.Header.Get("Location")
}

type chunkOptions struct {
// Content-Range header to set when pushing chunks
contentRange string
}

func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader, options chunkOptions) (*http.Response, error) {
func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader) (*http.Response, error) {
u, err := url.Parse(uploadURLBase)
if err != nil {
t.Fatalf("unexpected error parsing pushLayer url: %v", err)
Expand All @@ -2558,9 +2527,6 @@ func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader, options chu
t.Fatalf("unexpected error creating new request: %v", err)
}
req.Header.Set("Content-Type", "application/octet-stream")
if options.contentRange != "" {
req.Header.Set("Content-Range", options.contentRange)
}

resp, err := http.DefaultClient.Do(req)

Expand All @@ -2570,7 +2536,7 @@ func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader, options chu
func pushChunk(t *testing.T, ub *v2.URLBuilder, name reference.Named, uploadURLBase string, body io.Reader, length int64) (string, digest.Digest) {
digester := digest.Canonical.Digester()

resp, err := doPushChunk(t, uploadURLBase, io.TeeReader(body, digester.Hash()), chunkOptions{})
resp, err := doPushChunk(t, uploadURLBase, io.TeeReader(body, digester.Hash()))
if err != nil {
t.Fatalf("unexpected error doing push layer request: %v", err)
}
Expand Down
25 changes: 0 additions & 25 deletions registry/handlers/blobupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"

"github.com/distribution/distribution/v3"
dcontext "github.com/distribution/distribution/v3/context"
Expand Down Expand Up @@ -142,30 +141,6 @@ func (buh *blobUploadHandler) PatchBlobData(w http.ResponseWriter, r *http.Reque
return
}

cr := r.Header.Get("Content-Range")
cl := r.Header.Get("Content-Length")
if cr != "" && cl != "" {
start, end, err := parseContentRange(cr)
if err != nil {
buh.Errors = append(buh.Errors, errcode.ErrorCodeUnknown.WithDetail(err.Error()))
return
}
if start > end || start != buh.Upload.Size() {
buh.Errors = append(buh.Errors, v2.ErrorCodeRangeInvalid)
return
}

clInt, err := strconv.ParseInt(cl, 10, 64)
if err != nil {
buh.Errors = append(buh.Errors, errcode.ErrorCodeUnknown.WithDetail(err.Error()))
return
}
if clInt != (end-start)+1 {
buh.Errors = append(buh.Errors, v2.ErrorCodeSizeInvalid)
return
}
}

if err := copyFullPayload(buh, w, r, buh.Upload, -1, "blob PATCH"); err != nil {
buh.Errors = append(buh.Errors, errcode.ErrorCodeUnknown.WithDetail(err.Error()))
return
Expand Down

0 comments on commit 4741041

Please sign in to comment.