| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "config.h" |
| 20 |
|
| 21 |
#include <stdint.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <libgen.h> |
| 25 |
#include <time.h> |
| 26 |
|
| 27 |
#include <espeak-ng/espeak_ng.h> |
| 28 |
#define BOLDRED(x) "\x1b[31m\x1b[1m" x "\x1b[0m" |
| 29 |
|
| 30 |
static int initialized = 0; |
| 31 |
|
| 32 |
static int |
| 33 |
espeak_callback(short *data, int samples, espeak_EVENT *events) |
| 34 |
{ |
| 35 |
(void)data; |
| 36 |
(void)samples; |
| 37 |
(void)events; |
| 38 |
|
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 43 |
{ |
| 44 |
int buflength = size+1; |
| 45 |
if (!initialized) |
| 46 |
{ |
| 47 |
int options = espeakINITIALIZE_DONT_EXIT; |
| 48 |
espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, buflength, PATH_ESPEAK_DATA, options); |
| 49 |
espeak_SetSynthCallback(espeak_callback); |
| 50 |
const char *lang = getenv("FUZZ_VOICE"); |
| 51 |
if (lang == NULL) |
| 52 |
{ |
| 53 |
fprintf(stderr, "\n" BOLDRED("[Please set up FUZZ_VOICE env var before starting fuzzer]") "\n\n"); |
| 54 |
exit(1); |
| 55 |
} |
| 56 |
if (espeak_SetVoiceByName(lang) != EE_OK) |
| 57 |
{ |
| 58 |
fprintf(stderr, "\n" BOLDRED("[Please supply a valid voice in FUZZ_VOICE]") "\n\n"); |
| 59 |
exit(1); |
| 60 |
} |
| 61 |
initialized = 1; |
| 62 |
fprintf(stderr, "VOICE FUZZED = %s\n", lang); |
| 63 |
} |
| 64 |
char *mutable_data = strndup((char *)data, size); |
| 65 |
if (!mutable_data) |
| 66 |
{ |
| 67 |
perror("malloc"); |
| 68 |
exit(1); |
| 69 |
} |
| 70 |
unsigned int position = 0, position_type = POS_CHARACTER, end_position = 0 , synth_flags = espeakCHARS_AUTO; |
| 71 |
espeak_Synth(mutable_data, buflength, position, position_type, end_position, |
| 72 |
synth_flags, NULL, NULL); |
| 73 |
free(mutable_data); |
| 74 |
|
| 75 |
return 0; |
| 76 |
} |