Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
17dd7cb7
Commit
17dd7cb7
authored
Sep 30, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only sniff the first 4096 bytes
parent
45d7c0c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
34 deletions
+7
-34
internal/git/git-http.go
internal/git/git-http.go
+7
-19
internal/git/git-http_test.go
internal/git/git-http_test.go
+0
-15
No files found.
internal/git/git-http.go
View file @
17dd7cb7
...
...
@@ -20,13 +20,6 @@ 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
{
return
repoPreAuthorizeHandler
(
a
,
handleGetInfoRefs
)
}
...
...
@@ -122,18 +115,22 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
}
if
action
==
"git-upload-pack"
{
buffer
,
err
:=
bufferUploadPackRequest
(
r
.
Body
)
buffer
:=
&
bytes
.
Buffer
{}
// Only sniff on the first 4096 bytes: we assume that if we find no
// 'deepen' message in the first 4096 bytes there won't be one later
// either.
_
,
err
=
io
.
Copy
(
buffer
,
io
.
LimitReader
(
r
.
Body
,
4096
))
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
&
copyError
{
fmt
.
Errorf
(
"handlePostRPC: buffer git-upload-pack body: %v"
)})
return
}
isShallowClone
,
err
=
scanDeepen
(
bytes
.
NewReader
(
buffer
.
Bytes
()))
body
=
buffer
body
=
io
.
MultiReader
(
buffer
,
r
.
Body
)
if
err
!=
nil
{
// Do not pass on the error: our failure to parse the
// request body should not abort the request.
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"parseBody: %v"
,
err
))
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"parseBody
(non-fatal)
: %v"
,
err
))
}
}
else
{
...
...
@@ -199,12 +196,3 @@ func isExitError(err error) bool {
func
subCommand
(
rpc
string
)
string
{
return
strings
.
TrimPrefix
(
rpc
,
"git-"
)
}
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
{
err
=
fmt
.
Errorf
(
"request body too large (more than %d bytes)"
,
uploadPackRequestLimit
-
1
)
}
return
buffer
,
err
}
internal/git/git-http_test.go
deleted
100644 → 0
View file @
45d7c0c1
package
git
import
(
"bytes"
"testing"
)
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"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment