Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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-ce
Commits
a00a3460
Commit
a00a3460
authored
Sep 30, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't buffer unlimited data in memory
parent
23a16410
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
internal/git/git-http.go
internal/git/git-http.go
+13
-2
internal/git/git-http_test.go
internal/git/git-http_test.go
+16
-0
No files found.
internal/git/git-http.go
View file @
a00a3460
...
...
@@ -20,6 +20,8 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
const
uploadPackRequestLimit
=
1000000
func
GetInfoRefs
(
a
*
api
.
API
)
http
.
Handler
{
return
repoPreAuthorizeHandler
(
a
,
handleGetInfoRefs
)
}
...
...
@@ -115,8 +117,8 @@ func handlePostRPC(w http.ResponseWriter, r *http.Request, a *api.Response) {
}
if
action
==
"git-upload-pack"
{
buffer
:=
&
bytes
.
Buffer
{}
if
_
,
err
:=
io
.
Copy
(
buffer
,
r
.
Body
);
err
!=
nil
{
buffer
,
err
:=
bufferPostBody
(
r
.
Body
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
&
copyError
{
fmt
.
Errorf
(
"handlePostRPC: buffer git-upload-pack body: %v"
)})
return
}
...
...
@@ -192,3 +194,12 @@ func isExitError(err error) bool {
func
subCommand
(
rpc
string
)
string
{
return
strings
.
TrimPrefix
(
rpc
,
"git-"
)
}
func
bufferPostBody
(
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
0 → 100644
View file @
a00a3460
package
git
import
(
"bytes"
"testing"
)
func
TestBufferPostBodyLimiting
(
t
*
testing
.
T
)
{
_
,
err
:=
bufferPostBody
(
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