Commit 182b28d9 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Comments, better function name

parent a00a3460
......@@ -20,6 +20,11 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
// In the request body for POST /git-upload-pack, the client is telling
// git-upload-pack which objects is wants and which objects it already
// has. Each 'want' or 'have' is about 30 bytes. Limiting the total
// git-upload-pack request body size at 1000000 means that we allow for
// about 33000 want/have messages.
const uploadPackRequestLimit = 1000000
func GetInfoRefs(a *api.API) http.Handler {
......@@ -117,7 +122,7 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
}
if action == "git-upload-pack" {
buffer, err := bufferPostBody(r.Body)
buffer, err := bufferUploadPackRequest(r.Body)
if err != nil {
helper.Fail500(w, r, &copyError{fmt.Errorf("handlePostRPC: buffer git-upload-pack body: %v")})
return
......@@ -195,7 +200,7 @@ func subCommand(rpc string) string {
return strings.TrimPrefix(rpc, "git-")
}
func bufferPostBody(body io.Reader) (*bytes.Buffer, error) {
func bufferUploadPackRequest(body io.Reader) (*bytes.Buffer, error) {
buffer := &bytes.Buffer{}
n, err := io.Copy(buffer, &io.LimitedReader{R: body, N: uploadPackRequestLimit})
if err == nil && n == uploadPackRequestLimit {
......
......@@ -5,12 +5,11 @@ import (
"testing"
)
func TestBufferPostBodyLimiting(t *testing.T) {
_, err := bufferPostBody(bytes.NewReader(make([]byte, 2000000)))
func TestBbufferUploadPackRequestLimiting(t *testing.T) {
_, err := bufferUploadPackRequest(bytes.NewReader(make([]byte, 2000000)))
t.Log(err)
if err == nil {
t.Fatalf("expected an error, received nil")
}
}
......@@ -43,7 +43,7 @@ func pktLineSplitter(data []byte, atEOF bool) (advance int, token []byte, err er
if bytes.HasPrefix(data, []byte("0000")) {
// special case: "0000" terminator packet: return empty token
return 4, data[4:4], nil
return 4, data[:0], nil
}
// We have at least 4 bytes available so we can decode the 4-hex digit
......@@ -53,6 +53,7 @@ func pktLineSplitter(data []byte, atEOF bool) (advance int, token []byte, err er
return 0, nil, fmt.Errorf("pktLineSplitter: decode length: %v", err)
}
// Cast is safe because we requested an int-size number from strconv.ParseInt
pktLength := int(pktLength64)
if pktLength < 0 {
......@@ -66,5 +67,6 @@ func pktLineSplitter(data []byte, atEOF bool) (advance int, token []byte, err er
return 0, nil, nil // want more data
}
// return "pkt" token without length prefix
return pktLength, data[4:pktLength], nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment