| 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 |
|
| 26 |
#include <espeak-ng/espeak_ng.h> |
| 27 |
|
| 28 |
static int initialized = 0; |
| 29 |
|
| 30 |
static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) { |
| 31 |
(void)wav; |
| 32 |
(void)numsamples; |
| 33 |
(void)events; |
| 34 |
|
| 35 |
return 0; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
| 41 |
extern int LLVMFuzzerInitialize(const int* argc, char*** argv); |
| 42 |
|
| 43 |
char *filepath = NULL; |
| 44 |
|
| 45 |
extern int LLVMFuzzerInitialize(const int* argc, char*** argv) |
| 46 |
{ |
| 47 |
(void)argc; |
| 48 |
filepath = dirname(strdup((*argv)[0])); |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 53 |
if (!initialized) { |
| 54 |
const char *hasDataPath = getenv("ESPEAK_DATA_PATH"); |
| 55 |
if (!hasDataPath) { |
| 56 |
setenv("ESPEAK_DATA_PATH",filepath,0); |
| 57 |
} |
| 58 |
espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, 0); |
| 59 |
espeak_SetSynthCallback(SynthCallback); |
| 60 |
initialized = 1; |
| 61 |
} |
| 62 |
|
| 63 |
int synth_flags = espeakCHARS_UTF8 | espeakPHONEMES | espeakSSML; |
| 64 |
char *str = malloc(size+1); |
| 65 |
memcpy(str, data, size); |
| 66 |
str[size] = 0; |
| 67 |
espeak_Synth((char*) str, size + 1, 0, POS_CHARACTER, 0, |
| 68 |
synth_flags, NULL, NULL); |
| 69 |
free(str); |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |