From 566e904b332c5816c3b4c02a7cb618c6b217d980 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sun, 25 Mar 2018 12:52:22 +0100 Subject: [PATCH] LookupDict2: Fix searching entries longer than 128 This is a fix for https://github.com/nvaccess/nvda/issues/7740. With the addition of emoji support, dictionary entries can now be longer than 128 bytes. This fix makes sure the character is interpreted as an unsigned byte so it does not treat long entries as having a negative offset. Treating the offset as a signed byte (like in the previous code) could cause the hash chain search to loop indefinitely when processing certain input, like the Tamil characters in the NVDA issue noted above that is added as a test case to translate.test. --- src/libespeak-ng/dictionary.c | 2 +- tests/translate.test | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 2d159795..4bad719f 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -2607,7 +2607,7 @@ static const char *LookupDict2(Translator *tr, const char *word, const char *wor // This corresponds to the last matching entry in the *_list file. while (*p != 0) { - next = p + p[0]; + next = p + (p[0] & 0xff); if (((p[1] & 0x7f) != wlen) || (memcmp(word, &p[2], wlen & 0x3f) != 0)) { // bit 6 of wlen indicates whether the word has been compressed; so we need to match on this also. diff --git a/tests/translate.test b/tests/translate.test index 6dcf6384..5a584ef5 100755 --- a/tests/translate.test +++ b/tests/translate.test @@ -18,6 +18,9 @@ test_phonemes en " h@l'oU" "hello" # correct word stress test_phonemes en " s'VmTIN Imp'o@t@nt" "something important" +# bug: https://github.com/nvaccess/nvda/issues/7740 +test_phonemes ta " 'il." "ள்" + # bug: https://github.com/nvaccess/nvda/issues/7805 test_phonemes hi " r'UcI" "रुचि" test_phonemes hi " dUk'a:n" "दुकान"