Skip to content

Commit

Permalink
Adds a fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
jesslatimer committed Apr 1, 2023
1 parent d2c9edc commit 4e156ab
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/fuzz_rdflib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3

import atheris

with atheris.instrument_imports():
from rdflib import Graph
from rdflib.plugins.parsers.notation3 import BadSyntax
from rdflib.exceptions import ParserError
import sys
from xml.sax import SAXParseException


def TestOneInput(data):
# arbitrary byte 'data' created by atheris that mutates each time
# this allows you to manipulate the 'data' into strings, integers, lists of integers etc.
fdp = atheris.FuzzedDataProvider(data)

format_list = ["xml", "trix", "turtle", "n3", "nt"]
g = Graph()
try:
g.parse(format=fdp.PickValueInList(format_list),
data=fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1, 100)))
# Data generated is not appropriate, so ignore BadSyntax, SAXParseException and ParserError
except (BadSyntax, SAXParseException, ParserError):
pass


atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()

0 comments on commit 4e156ab

Please sign in to comment.