Debian Codegraph @

tests/fuzzing/synth_fuzzer.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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 #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 }