Skip to content

Commit

Permalink
Put a limit on the max body size for fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Jan 16, 2024
1 parent 435faf8 commit c205a25
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ 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*1024)

f.Fuzz(func(t *testing.T, body []byte, max int) {
if max > 10*1024*1024 { // Skip limits higher than 10MB.
return
}

_ = res.ReadLimitBody(bufio.NewReader(bytes.NewReader(body)), max)
w := bytes.Buffer{}
_, _ = res.WriteTo(&w)
Expand All @@ -67,6 +71,10 @@ 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*1024)

f.Fuzz(func(t *testing.T, body []byte, max int) {
if max > 10*1024*1024 { // Skip limits higher than 10MB.
return
}

_ = req.ReadLimitBody(bufio.NewReader(bytes.NewReader(body)), max)
w := bytes.Buffer{}
_, _ = req.WriteTo(&w)
Expand Down

0 comments on commit c205a25

Please sign in to comment.