From f9f213efa62699099862c267714df40c208cce90 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Sat, 18 May 2024 10:30:23 +0200 Subject: [PATCH] Prevent OOM when fuzzing --- fuzz_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fuzz_test.go b/fuzz_test.go index ba1737a493..3a23ee45c7 100644 --- a/fuzz_test.go +++ b/fuzz_test.go @@ -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 } @@ -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 }