Skip to content

Commit

Permalink
Update Fuzz Harness
Browse files Browse the repository at this point in the history
  • Loading branch information
ebell495 authored and ForAllSecure Mayhem Bot committed Jul 3, 2024
1 parent 66337ec commit 2f80671
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion fuzz/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
apt-get clean

# pytest needs to be installed through pip to make sure we have a recent version
RUN pip3 install pytest atheris
RUN pip3 install pytest atheris segments dlinfo

# tests expect python to be available as executable 'python' not 'python3'
RUN ln -s /usr/bin/python3 /usr/bin/python
Expand Down
35 changes: 14 additions & 21 deletions fuzz/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
import sys
import os
import atheris
# old_stdout = sys.stdout # backup current stdout
# sys.stdout = open(os.devnull, "w")
with atheris.instrument_imports():
from phonemizer.backend import EspeakBackend, FestivalBackend
# sys.stdout = old_stdout
# from phonemizer import phonemize
# from phonemizer.backend import EspeakBackend, FestivalBackend

from phonemizer.backend import EspeakBackend, FestivalBackend

# Initilize the backends separatly
# Running phonemizer repeatly increases the memory usage
Expand All @@ -18,21 +13,19 @@

@atheris.instrument_func
def TestOneInput(data):
barray = bytearray(data)
# espeak.phonemize(str(data).split(" "))
if len(barray) > 0:
# Choose the backend to use based on the first input byte
r = barray[0]
if r % 2 == 0:
# Make sure to remove the first byte otherwise this will only every test this backend with the first byte being even
del barray[0]
espeak.phonemize(str(data).split(' '))
else:
del barray[0]
festival.phonemize(str(data).split(' '))
fdp = atheris.FuzzedDataProvider(data)

if len(data) < 1:
return

option = fdp.ConsumeBytes(1)[0]
in_string = fdp.ConsumeUnicodeNoSurrogates(len(data))

if option % 2 == 0:
espeak.phonemize(in_string.split(" "))
else:
espeak.phonemize(str(data).split(' '))
festival.phonemize(str(data).split(' '))
festival.phonemize(in_string.split(" "))

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

0 comments on commit 2f80671

Please sign in to comment.