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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  37. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
  38. {
  39. int buflength = size+1;
  40. if (!initialized)
  41. {
  42. int options = espeakINITIALIZE_DONT_EXIT;
  43. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, buflength, PATH_ESPEAK_DATA, options);
  44. espeak_ng_SetRandSeed(1);
  45. espeak_SetSynthCallback(espeak_callback);
  46. const char *lang = getenv("FUZZ_VOICE");
  47. if (lang == NULL)
  48. {
  49. fprintf(stderr, "\n" BOLDRED("[Please set up FUZZ_VOICE env var before starting fuzzer]") "\n\n");
  50. exit(1);
  51. }
  52. if (espeak_SetVoiceByName(lang) != EE_OK)
  53. {
  54. fprintf(stderr, "\n" BOLDRED("[Please supply a valid voice in FUZZ_VOICE]") "\n\n");
  55. exit(1);
  56. }
  57. initialized = 1;
  58. fprintf(stderr, "VOICE FUZZED = %s\n", lang);
  59. }
  60. char *mutable_data = strndup((char *)data, size);
  61. if (!mutable_data)
  62. {
  63. perror("malloc");
  64. exit(1);
  65. }
  66. unsigned int position = 0, position_type = POS_CHARACTER, end_position = 0 , synth_flags = espeakCHARS_AUTO;
  67. espeak_Synth(mutable_data, buflength, position, position_type, end_position,
  68. synth_flags, NULL, NULL);
  69. free(mutable_data);
  70. return 0;
  71. }