Skip to content

Commit f9f213e

Browse files
Prevent OOM when fuzzing
1 parent aadadb9 commit f9f213e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fuzz_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func FuzzResponseReadLimitBody(f *testing.F) {
4343
f.Add([]byte("HTTP/1.1 200 OK\r\nContent-Type: aa\r\nContent-Length: 10\r\n\r\n9876543210"), 1024)
4444

4545
f.Fuzz(func(t *testing.T, body []byte, max int) {
46-
if len(body) > 10*1024 || max > 10*1024 {
46+
if len(body) > 1024*1024 || max > 1024*1024 {
47+
return
48+
}
49+
// Only test with a max for the body, otherwise a very large Content-Length will just OOM.
50+
if max <= 0 {
4751
return
4852
}
4953

@@ -58,7 +62,11 @@ func FuzzRequestReadLimitBody(f *testing.F) {
5862
f.Add([]byte("POST /a HTTP/1.1\r\nHost: a.com\r\nTransfer-Encoding: chunked\r\nContent-Type: aa\r\n\r\n6\r\nfoobar\r\n3\r\nbaz\r\n0\r\nfoobar\r\n\r\n"), 1024)
5963

6064
f.Fuzz(func(t *testing.T, body []byte, max int) {
61-
if len(body) > 10*1024 || max > 10*1024 {
65+
if len(body) > 1024*1024 || max > 1024*1024 {
66+
return
67+
}
68+
// Only test with a max for the body, otherwise a very large Content-Length will just OOM.
69+
if max <= 0 {
6270
return
6371
}
6472

0 commit comments

Comments
 (0)