eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssml-fuzzer.c 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include "config.h"
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <libgen.h>
  23. #include <espeak-ng/espeak_ng.h>
  24. static int initialized = 0;
  25. static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
  26. (void)wav; // unused
  27. (void)numsamples; // unused
  28. (void)events; // unused
  29. return 0;
  30. }
  31. /* See http://llvm.org/docs/LibFuzzer.html */
  32. extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  33. extern int LLVMFuzzerInitialize(const int* argc, char*** argv);
  34. char *filepath = NULL;
  35. int LLVMFuzzerInitialize(const int* argc, char*** argv) {
  36. (void)argc; // unused
  37. filepath = dirname(strdup((*argv)[0]));
  38. return 0;
  39. }
  40. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  41. if (!initialized) {
  42. const char *hasDataPath = getenv("ESPEAK_DATA_PATH");
  43. if (!hasDataPath) {
  44. setenv("ESPEAK_DATA_PATH",filepath,0);
  45. }
  46. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, 0);
  47. espeak_ng_SetRandSeed(1);
  48. espeak_SetSynthCallback(SynthCallback);
  49. initialized = 1;
  50. }
  51. int synth_flags = espeakCHARS_UTF8 | espeakPHONEMES | espeakSSML;
  52. char *str = malloc(size+1);
  53. memcpy(str, data, size);
  54. str[size] = 0;
  55. espeak_Synth((char*) str, size + 1, 0, POS_CHARACTER, 0,
  56. synth_flags, NULL, NULL);
  57. free(str);
  58. return 0;
  59. }