Skip to content

Commit faca78f

Browse files
committed
Adds a fuzz test
1 parent d2c9edc commit faca78f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/fuzz_rdflib.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/python3
2+
3+
import atheris
4+
5+
with atheris.instrument_imports():
6+
from rdflib import Graph
7+
from rdflib.plugins.parsers.notation3 import BadSyntax
8+
from rdflib.exceptions import ParserError
9+
import sys
10+
from xml.sax import SAXParseException
11+
12+
13+
def test_one_input(data):
14+
# arbitrary byte 'data' created by atheris that mutates each time
15+
# this allows you to manipulate the 'data' into strings, integers, lists of integers etc.
16+
fdp = atheris.FuzzedDataProvider(data)
17+
18+
format_list = ["xml", "trix", "turtle", "n3", "nt"]
19+
g = Graph()
20+
try:
21+
g.parse(format=fdp.PickValueInList(format_list),
22+
data=fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1, 100)))
23+
# Data generated is not appropriate, so ignore BadSyntax, SAXParseException and ParserError
24+
except (BadSyntax, SAXParseException, ParserError):
25+
pass
26+
27+
28+
atheris.Setup(sys.argv, test_one_input)
29+
atheris.Fuzz()

0 commit comments

Comments
 (0)