Debian Codegraph @

tests/ssml-fuzzer.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 Sascha Brawer
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write see:
16 * <http://www.gnu.org/licenses/>.
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; // unused
32 (void)numsamples; // unused
33 (void)events; // unused
34
35 return 0;
36 }
37
38
39 /* See http://llvm.org/docs/LibFuzzer.html */
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; // unused
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 }