test: oss-fuzz support for fuzzing

Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
This commit is contained in:
Arjun Singh
2023-05-12 17:58:37 +05:30
committed by Leander Beernaert
parent cfca429067
commit cb8174dbfd
4 changed files with 92 additions and 0 deletions

View File

@ -110,3 +110,23 @@ func TestReadHeaderBodyInvalidHeader(t *testing.T) {
assert.Equal(t, 0, header.Len())
assert.Equal(t, []byte(data), body)
}
func FuzzReadHeaderBody(f *testing.F) {
header := `Content-Type: application/msword; name="=E5=B8=B6=E6=9C=89=E5=A4=96=E5=9C=8B=E5=AD=97=E7=AC=A6=E7=9A=84=E9=99=84=E4=
=BB=B6.DOC"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="=E5=B8=B6=E6=9C=89=E5=A4=96=E5=9C=8B=E5=AD=97=E7=AC=A6=E7=9A=84=E9=99=84=E4=
=BB=B6.DOC"
Content-ID: <>
`
data0 := "key: value\r\n\r\nbody\n"
data1 := "key: value\r\n\r\nbody\n"
f.Add([]byte(header))
f.Add([]byte(data0))
f.Add([]byte(data1))
f.Fuzz(func(t *testing.T, b []byte) {
_, _, _ = readHeaderBody(b)
})
}

View File

@ -18,6 +18,7 @@
package parser
import (
"bytes"
"io"
"os"
"path/filepath"
@ -50,3 +51,18 @@ func getFileAsString(filename string) string {
return string(b)
}
func FuzzNewParser(f *testing.F) {
inSeed1, err1 := os.ReadFile(filepath.Join("testdata", "text_html_octet_attachment.eml"))
inSeed2, err2 := os.ReadFile(filepath.Join("testdata", "complex_structure.eml"))
require.NoError(f, err1)
require.NoError(f, err2)
f.Add(inSeed1)
f.Add(inSeed2)
f.Fuzz(func(t *testing.T, data []byte) {
_, _ = New(bytes.NewReader(data))
})
}