Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
ee154f5d
Commit
ee154f5d
authored
Apr 21, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mime/multipart: limit line length to prevent abuse
Fixes #1528 R=rsc CC=golang-dev
https://golang.org/cl/4425060
parent
256df10e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
multipart.go
src/pkg/mime/multipart/multipart.go
+4
-2
multipart_test.go
src/pkg/mime/multipart/multipart_test.go
+32
-0
No files found.
src/pkg/mime/multipart/multipart.go
View file @
ee154f5d
...
...
@@ -97,10 +97,11 @@ func newPart(mr *multiReader) (bp *Part, err os.Error) {
func
(
bp
*
Part
)
populateHeaders
()
os
.
Error
{
for
{
line
,
err
:=
bp
.
mr
.
bufReader
.
ReadString
(
'\n'
)
line
Bytes
,
err
:=
bp
.
mr
.
bufReader
.
ReadSlice
(
'\n'
)
if
err
!=
nil
{
return
err
}
line
:=
string
(
lineBytes
)
if
line
==
"
\n
"
||
line
==
"
\r\n
"
{
return
nil
}
...
...
@@ -179,11 +180,12 @@ func (mr *multiReader) eof() bool {
}
func
(
mr
*
multiReader
)
readLine
()
bool
{
line
,
err
:=
mr
.
bufReader
.
ReadString
(
'\n'
)
line
Bytes
,
err
:=
mr
.
bufReader
.
ReadSlice
(
'\n'
)
if
err
!=
nil
{
// TODO: care about err being EOF or not?
return
false
}
line
:=
string
(
lineBytes
)
mr
.
bufferedLine
=
&
line
return
true
}
...
...
src/pkg/mime/multipart/multipart_test.go
View file @
ee154f5d
...
...
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"json"
"os"
"regexp"
"strings"
"testing"
...
...
@@ -205,3 +206,34 @@ func TestVariousTextLineEndings(t *testing.T) {
}
}
type
maliciousReader
struct
{
t
*
testing
.
T
n
int
}
const
maxReadThreshold
=
1
<<
20
func
(
mr
*
maliciousReader
)
Read
(
b
[]
byte
)
(
n
int
,
err
os
.
Error
)
{
mr
.
n
+=
len
(
b
)
if
mr
.
n
>=
maxReadThreshold
{
mr
.
t
.
Fatal
(
"too much was read"
)
return
0
,
os
.
EOF
}
return
len
(
b
),
nil
}
func
TestLineLimit
(
t
*
testing
.
T
)
{
mr
:=
&
maliciousReader
{
t
:
t
}
r
:=
NewReader
(
mr
,
"fooBoundary"
)
part
,
err
:=
r
.
NextPart
()
if
part
!=
nil
{
t
.
Errorf
(
"unexpected part read"
)
}
if
err
==
nil
{
t
.
Errorf
(
"expected an error"
)
}
if
mr
.
n
>=
maxReadThreshold
{
t
.
Errorf
(
"expected to read < %d bytes; read %d"
,
maxReadThreshold
,
mr
.
n
)
}
}
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