Skip to content

Commit

Permalink
Prevent OOM when fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed May 18, 2024
1 parent aadadb9 commit f9f213e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func FuzzResponseReadLimitBody(f *testing.F) {
f.Add([]byte("HTTP/1.1 200 OK\r\nContent-Type: aa\r\nContent-Length: 10\r\n\r\n9876543210"), 1024)

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

Expand All @@ -58,7 +62,11 @@ func FuzzRequestReadLimitBody(f *testing.F) {
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)

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

Expand Down

0 comments on commit f9f213e

Please sign in to comment.