Coverage Report

Created: 2026-04-30 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/espeak-ng/tests/ssml-fuzzer.c
Line
Count
Source
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
26
#include <espeak-ng/espeak_ng.h>
27
28
static int initialized = 0;
29
30
7.06M
static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
31
7.06M
  (void)wav; // unused
32
7.06M
  (void)numsamples; // unused
33
7.06M
  (void)events; // unused
34
35
7.06M
  return 0;
36
7.06M
}
37
38
39
/* See http://llvm.org/docs/LibFuzzer.html */
40
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
41
extern int LLVMFuzzerInitialize(const int* argc, char*** argv);
42
43
char *filepath = NULL;
44
45
2
int LLVMFuzzerInitialize(const int* argc, char*** argv) {
46
2
  (void)argc; // unused
47
2
  filepath = dirname(strdup((*argv)[0]));
48
2
  return 0;
49
2
}
50
51
2.98k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
52
2.98k
  if (!initialized) {
53
1
    const char *hasDataPath = getenv("ESPEAK_DATA_PATH");
54
1
    if (!hasDataPath) {
55
1
      setenv("ESPEAK_DATA_PATH",filepath,0);
56
1
    }
57
1
    espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, 0);
58
1
    espeak_ng_SetRandSeed(1);
59
1
    espeak_SetSynthCallback(SynthCallback);
60
1
    initialized = 1;
61
1
  }
62
63
2.98k
  int synth_flags = espeakCHARS_UTF8 | espeakPHONEMES | espeakSSML;
64
2.98k
       char *str = malloc(size+1);
65
2.98k
       memcpy(str, data, size);
66
2.98k
       str[size] = 0;
67
2.98k
       espeak_Synth((char*) str, size + 1, 0, POS_CHARACTER, 0,
68
2.98k
               synth_flags, NULL, NULL);
69
2.98k
       free(str);
70
71
2.98k
  return 0;
72
2.98k
}