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.

synth_fuzzer.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <time.h>
  24. #include <espeak-ng/espeak_ng.h>
  25. #define BOLDRED(x) "\x1b[31m\x1b[1m" x "\x1b[0m"
  26. static int initialized = 0;
  27. static int
  28. espeak_callback(short *data, int samples, espeak_EVENT *events)
  29. {
  30. (void)data;
  31. (void)samples;
  32. (void)events;
  33. return 0;
  34. }
  35. /* See http://llvm.org/docs/LibFuzzer.html */
  36. extern int LLVMFuzzerRunDriver(int *argc, char ***argv,
  37. int (*UserCb)(const uint8_t *Data, size_t Size));
  38. extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  39. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
  40. {
  41. int buflength = size+1;
  42. if (!initialized)
  43. {
  44. int options = espeakINITIALIZE_DONT_EXIT;
  45. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, buflength, PATH_ESPEAK_DATA, options);
  46. espeak_SetSynthCallback(espeak_callback);
  47. const char *lang = getenv("FUZZ_VOICE");
  48. if (lang == NULL)
  49. {
  50. fprintf(stderr, "\n" BOLDRED("[Please set up FUZZ_VOICE env var before starting fuzzer]") "\n\n");
  51. exit(1);
  52. }
  53. if (espeak_SetVoiceByName(lang) != EE_OK)
  54. {
  55. fprintf(stderr, "\n" BOLDRED("[Please supply a valid voice in FUZZ_VOICE]") "\n\n");
  56. exit(1);
  57. }
  58. initialized = 1;
  59. fprintf(stderr, "VOICE FUZZED = %s\n", lang);
  60. }
  61. char *mutable_data = strndup((char *)data, size);
  62. if (!mutable_data)
  63. {
  64. perror("malloc");
  65. exit(1);
  66. }
  67. unsigned int position = 0, position_type = POS_CHARACTER, end_position = 0 , synth_flags = espeakCHARS_AUTO;
  68. espeak_Synth(mutable_data, buflength, position, position_type, end_position,
  69. synth_flags, NULL, NULL);
  70. free(mutable_data);
  71. return 0;
  72. }
  73. int main(int argc, char *argv[]) {
  74. LLVMFuzzerRunDriver(&argc, &argv, LLVMFuzzerTestOneInput);
  75. }