commit 249e36585a7bee439af8302c6556f74187e2c62f
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Jul 22 00:08:33 2022 +0200

    compileTranslationTable: Check replacement characters []
    
    We can check at compile-time that we always have exactly one startReplace
    character followed by one endReplace.
    
    This is needed otherwise when a table misses the endReplace (as
    tables/hu-hu-g1_braille_input.cti fixed here), match has
    startReplace != -1 but endReplace == -1, and eventually passDoAction
    sets newPos to -1, and other functions such as setBefore underflow the
    buffer.

diff --git a/liblouis/compileTranslationTable.c b/liblouis/compileTranslationTable.c
index 2781fd3f..cbc6ae16 100644
--- a/liblouis/compileTranslationTable.c
+++ b/liblouis/compileTranslationTable.c
@@ -1875,6 +1875,7 @@ compilePassOpcode(const FileInfo *file, TranslationTableOpcode opcode, int nobac
 	CharsString passLine;
 	int passLinepos = 0;
 	TranslationTableCharacterAttributes passAttributes;
+	int replacing = 0;
 	passHoldString.length = 0;
 	for (k = file->linepos; k < file->linelen; k++)
 		passHoldString.chars[passHoldString.length++] = file->line[k];
@@ -1971,14 +1972,24 @@ compilePassOpcode(const FileInfo *file, TranslationTableOpcode opcode, int nobac
 			}
 			break;
 		case pass_startReplace:
+			if (replacing) {
+				compileError(file, "nested replacement statements");
+				return 0;
+			}
 			if (!appendInstructionChar(
 						file, passInstructions, &passIC, pass_startReplace))
 				return 0;
+			replacing = 1;
 			passLinepos++;
 			break;
 		case pass_endReplace:
+			if (!replacing) {
+				compileError(file, "unexpected end of replacement");
+				return 0;
+			}
 			if (!appendInstructionChar(file, passInstructions, &passIC, pass_endReplace))
 				return 0;
+			replacing = 0;
 			passLinepos++;
 			break;
 		case pass_variable:
@@ -2129,6 +2140,10 @@ compilePassOpcode(const FileInfo *file, TranslationTableOpcode opcode, int nobac
 		case pass_endTest:
 			if (!appendInstructionChar(file, passInstructions, &passIC, pass_endTest))
 				return 0;
+			if (replacing) {
+				compileError(file, "expected end of replacement");
+				return 0;
+			}
 			passLinepos++;
 			break;
 		default:
diff --git a/tables/hu-hu-g1_braille_input.cti b/tables/hu-hu-g1_braille_input.cti
index 72162129..24c0047f 100644
--- a/tables/hu-hu-g1_braille_input.cti
+++ b/tables/hu-hu-g1_braille_input.cti
@@ -108,7 +108,7 @@ noback pass2 @5-23456 @46-1356
 #Compatibility purposes handle older braille 5-4 dot combination when the user trying typing the 5-4 dot combination, and not known yet the new changed 5-14 dot combination
 nofor always ` 5-4
 noback always ` 5-4
-noback context $a1-30["`" @5-4
+noback context $a1-30["`"] @5-4
 noback pass2 @5-4 @5-14
 nofor context @5-4 "`"	Handle the backtranslation too
 
