From f60a27a7cd16486eec5fe2e5207184d1060c0f5c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 2 Jul 2022 01:56:25 +0200 Subject: [PATCH] Do not overflow ph_buf With emojis, phoneme strings can be very long --- src/libespeak-ng/dictionary.c | 6 ++++-- src/libespeak-ng/translate.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index c7c6cf89..4cd87ded 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -2228,7 +2229,7 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c int dict_flags0 = 0; MatchRecord match1; MatchRecord match2; - char ph_buf[40]; + char ph_buf[N_PHONEME_BYTES]; char word_copy[N_WORD_BYTES]; static const char str_pause[2] = { phonPAUSE_NOLINK, 0 }; @@ -2660,8 +2661,9 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor phonetic[0] = 0; phoneme_len = 0; } else { - strcpy(phonetic, p); phoneme_len = strlen(p); + assert(phoneme_len < N_PHONEME_BYTES); + strcpy(phonetic, p); p += (phoneme_len + 1); } diff --git a/src/libespeak-ng/translate.h b/src/libespeak-ng/translate.h index 0be35ce5..dfa5e118 100644 --- a/src/libespeak-ng/translate.h +++ b/src/libespeak-ng/translate.h @@ -39,6 +39,7 @@ extern "C" #define N_WORD_PHONEMES 200 // max phonemes in a word #define N_WORD_BYTES 160 // max bytes for the UTF8 characters in a word +#define N_PHONEME_BYTES 160 // max bytes for a phoneme #define N_CLAUSE_WORDS 300 // max words in a clause #define N_TR_SOURCE 800 // the source text of a single clause (UTF8 bytes)