ssml-fuzzer.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <espeak-ng/espeak_ng.h>
  22. static int initialized = 0;
  23. static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
  24. /* prevent warning for unused arguments */
  25. (void) wav;
  26. (void) numsamples;
  27. (void) events;
  28. return 0;
  29. }
  30. /* See http://llvm.org/docs/LibFuzzer.html */
  31. extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  32. extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  33. if (!initialized) {
  34. espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, 0);
  35. espeak_SetSynthCallback(SynthCallback);
  36. initialized = 1;
  37. }
  38. int synth_flags = espeakCHARS_UTF8 | espeakPHONEMES | espeakSSML;
  39. espeak_Synth((char*) data, size + 1, 0, POS_CHARACTER, 0,
  40. synth_flags, NULL, NULL);
  41. return 0;
  42. }