From 22005d5c86cf71fb60edea852cc0b1dacc9f0fbf Mon Sep 17 00:00:00 2001 From: Valdis Vitolins Date: Fri, 25 Mar 2022 22:44:35 +0200 Subject: [PATCH 1/2] Test before pull request #1126: MatchRule: Do not overflow the text --- tests/translate.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/translate.test b/tests/translate.test index 056020ac..7b754f5e 100755 --- a/tests/translate.test +++ b/tests/translate.test @@ -33,6 +33,9 @@ test_phon hi "r'UcI" "रुचि" test_phon hi "dUk'a:n" "दुकान" test_phon hi "ka:n'u:n" "कानून" +# pull request: MatchRule: Do not overflow the text https://github.com/espeak-ng/espeak-ng/pull/1126 +test_phon en "k'apIt@Lz" "capitals" + # bug: https://github.com/espeak-ng/espeak-ng/issues/824 test_phon ru "(en)s'i:(ru) n'ojl t'otS;ka# v'os;E2md;E2s;ats;'ejm m;,IlI;'onof_! p;,It;s'ot SE2z;d;d;Is;'jatd;'evI3t; t'ys;VtS;_! dv;'es;t;I p;Vd;d;Is;'jattR;'i p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I ojd;'in p@-rats'Ent dv;'es;t;I t'otS;ka# t@-r;'ittsat;S'Es;t; t'ys;VtS;_! vOs;Ims'ot s;Imn'AttsVt; p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# dv;'e t'ys;VdZ; d;E2v;Itn'AttsVt; p@-rats'Ent dv;'es;t;I ojd;'in t'otS;ka# n'ojl tR;'iv'os;E#m_!s;'ejm d;'evI3t;S'Es;t;_!tR;'i p@-rats'Ent dv'A (en)s'i:(ru) ojd;'in t'otS;ka# n'ojl tR;'iv'os;E#m_!s;'ejm d;'evI3t;S'Es;t;_!tR;'i p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I ojd;'in p@-rats'Ent dv;'es;t;I t'otS;ka# tS;It'yr;E2sta# d;E2v;Itn'AttsVt; t'ys;VtS;_! S,E#s;t;s'ot t@-r;'ittsat;s;'ejm p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# n'ojldv'A_! tR;'is;'ejm_!p;'jat; p@-rats'Ent dv'AttsVt; (en)s'i:(ru) p@-rats'Ent dv;'es;t;I t'otS;ka# t@-r;'ittsVt; t'ys;VtS;_! v'os;E2md;E2s;ats;'ejm p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# n'ojltS;It'yR;I_! p;'jat;Vjd;'in_!tS;It'yR;I p@-rats'Ent dv;'es;t;I t'otS;ka# p;,It;s'ot v'os;E2md;E2s;atdv;'e t'ys;VtS;_! s;,Ims'ot t@-r;'ittsat;d;'evI3t; p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# dv;'es;t;I SE#stn'AttsVt; t'ys;VtS;_! dev;ats'ot s'o@-*Okdv'A p@-rats'Ent dv;'es;t;I t'otS;ka# s;,Ims'ot p;Vd;d;Is;'jat t'ys;VtS;_! p;,It;s'ot d;E2v;In'ostOtR;'i p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# tS;It'yr;E2sta# s;'emd;E2s;Vt t'ys;VtS;_! t@-r;'ista# v'os;E2m p@-rats'Ent dv;'es;t;I t'otS;ka# n'ojld;'evI3t;_! p;'jat;n'ojl_!dv'A p@-rats'Ent dv'A (en)s'i:(ru) n'ojl t'otS;ka# st'o s'o@-*Okdv;'e t'ys;VtS;_! p;,It;s'ot s;Imn'AttsVt; p@-rats'Ent dv'A (en)s'i:(ru) v'os;E2m t'otS;ka# vOs;Ims'ot dv'Attsat;d;'evI3t; t'ys;VtS;_! s;,Ims'ot SE2z;d;d;Is;'jatv'os;E2m p@-rats'Ent dv'AttsVt; (en)s'i:(ru) p@-rats'Ent dv;'es;t;I p@-rats'Ent dv'A (en)s'i:(ru) p;'jat; t'otS;ka# S,E#s;t;s'ot SE2z;d;d;Is;'jatd;'evI3t; t'ys;VtS;_! s'o@-*Okojd;'in p@-rats'Ent dv'AttsVt; tS;It'yR;I t'otS;ka# p;Vd;d;Is;'jatd;'evI3t; t'ys;VtS;_! S,E#s;t;s'ot d;E2v;In'ostOd;'evI3t; p@-rats'Ent dv'A (en)s'i:(ru) d;'es;It; t'otS;ka# dv'A m;,IlI;'onof_! S,E#s;t;s'ot p;Vd;d;Is;'jatdv;'e t'ys;VtS;_! t@-r;'ista# d;E2v;In'ostOojd;'in p@-rats'Ent dv'AttsVt; d;'es;It; t'otS;ka# dv;'es;t;I SE2z;d;d;Is;'jatp;'jat; t'ys;VtS;_! dv;'es;t;I t@-r;'ittsat;v'os;E2m p@-rats'Ent dv'A (en)s'i:(ru) d;'es;It; t'otS;ka# dv'A m;,IlI;'onof_! S,E#s;t;s'ot p;Vd;d;Is;'jatdv;'e t'ys;VtS;_! t@-r;'ista# d;E2v;In'ostOojd;'in p@-rats'Ent dv'AttsVt; (en)z'Ed(ru) p@-rats'Ent dv'AttsVt; (en)'Em(ru) p@-rats'Ent dv;'e t'ys;VdZ; d;'es;It; t'otS;ka# n'ojltR;'i_!s;'ejm v'os;E#mS'Es;t;_!p;'jat; p@-rats'Ent dv'A (en)s'i:(ru) d;E2v;Itn'AttsVt; t'otS;ka# s;,Ims'ot d;E2v;In'ostOv'os;E2m t'ys;VtS;_! p;,It;s'ot t@-r;'ittsat;s;'ejm p@-rats'Ent dv'AttsVt; (en)v'i:(ru) p@-rats'Ent dv;'es;t;I ojd;'in t'otS;ka# st'o s;'emd;E2s;VttS;It'yR;I t'ys;VtS;_! st'o v'os;E2md;E2s;atv'os;E2m p@-rats'Ent dv'AttsVt; (en)'eI(ru) p@-rats'Ent dv;'es;t;I ojd;'in t'otS;ka# tS;It'yr;E2sta# v'os;E2md;E2s;atv'os;E2m t'ys;VtS;_! p;,It;s'ot d;E2v;Itn'AttsVt; p@-rats'Ent dv'A (en)s'i:(ru) ojd;'in t'otS;ka# tS;It'yr;E2sta# v'os;E2md;E2s;atv'os;E2m t'ys;VtS;_! p;,It;s'ot d;E2v;Itn'AttsVt; p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I p@-rats'Ent dv;'es;t;I ojd;'in p@-rats'Ent dv;'es;t;I t'otS;ka# vOs;Ims'ot p;Vd;d;Is;'jats;'ejm t'ys;VtS;" "C0.87569253%200%200%201%200.36817%2C-0.2019%201.0387963%2C1.0387963%200%200%201%200.419637%2C-0.02375%20c%200.30087%2C0.04514%200.582739%2C0.216942%200.750593%2C0.470308%200.09502%2C0.142517%200.153603%2C0.308788%200.18844%2C0.478226%200.03484%2C0.168646%200.0475%2C0.340459%200.05701%2C0.513064%200.03167%2C0.601741%200.03167%2C1.205067%200.01426%2C1.808392%20-0.01426%2C0.526524%20-0.04355%2C1.0673%20-0.253366%2C1.549486%20-0.271575%2C0.619159%20-0.817101%2C1.08155%20-1.405383%2C1.414092%20a%205.5835296%2C5.5835296%200%200%201%20-1.257323%2C0.512272%20c%200.38163%2C1.219319%200.580363%2C2.56532%200.580363%2C3.93349%20a%2013.935071%2C13.935071%200%200%201%20-0.106901%2C1.682498%2010.264446%2C10.264446%200%200%200%205.054631%2C-8.829768%20c%200%2C-5.669041%20-4.59699%2C-10.2652391%20-10.265238%2C-10.2652391%20z%20M%2010.037865%2C19.798537%20v%201.174188%20a%201.488519%2C1.488519%200%200%201%200.857482%2C0.286619%201.3760882%2C1.3760882%200%200%201%200.440222%2C0.538402%20c%200.0966%2C0.213775%200.131432%2C0.456056%200.09184%2C0.687252%20a%201.1821057%2C1.1821057%200%200%201%20-0.262867%2C0.560568%201.3040376%2C1.3040376%200%200%201%20-0.502772%2C0.36263%201.3760882%2C1.3760882%200%200%201%20-0.623119%2C0.0966%20v%202.953287%20l%206.145683%2C-3.33175%20-6.145683%2C-3," "ru sum strings" From fe63f1b3e7a366b1b13161459750bdf706c07df8 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 20 Mar 2022 03:11:48 +0100 Subject: [PATCH 2/2] MatchRule: Do not overflow the text Some rules test against character not being of a certain type. That may match with the \0 end-of-text marker, and thus actually step over it and let MatchRule continue with uninitialized data after it, leading to potential random behavior. This commits fixes it by making sure that we don't read past that \0. This seems to be changing the pronunciation of "capitals" from k'apIt@Lz to k'apIt,alz, I don't know why, I guess the rule for it was actually bogus? --- src/libespeak-ng/dictionary.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index f3c65a02..a98caf54 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -1758,6 +1758,12 @@ static void MatchRule(Translator *tr, char *word[], char *word_start, int group_ if (distance_right > 18) distance_right = 19; last_letter_w = letter_w; + if (!post_ptr[-1]) { + // we had already reached the end of text! + // reading after that does not make sense, that cannot match + failed = 1; + break; + } letter_xbytes = utf8_in(&letter_w, post_ptr)-1; letter = *post_ptr++;