data: simplify and validate Japanese imports

This commit is contained in:
2026-08-12 17:32:28 +09:00
parent a8a6c3b455
commit 8d68e00f2b
11 changed files with 93 additions and 189 deletions

18
dict.c
View File

@@ -63,7 +63,7 @@ dictopen(char *path)
Hmap *h;
Biobuf *b;
Str key;
char *line, *tab;
char *line, *tab, *p, *e;
int len, lineno;
b = Bopen(path, OREAD);
@@ -81,13 +81,21 @@ dictopen(char *path)
continue;
}
tab = strchr(line, '\t');
if(tab == nil || tab >= line + len - 1){
free(line);
continue;
}
if(tab == nil || tab == line || tab >= line + len - 1 ||
strchr(tab+1, '\t') != nil)
die("malformed dictionary: %s:%d", path, lineno);
*tab = '\0';
if(utflen(line) > Maxrunes)
die("dictionary key too long: %s:%d", path, lineno);
for(p = tab+1; p < line+len; p = e+1){
e = memchr(p, ' ', line+len-p);
if(e == nil)
e = line+len;
if(utfnlen(p, e-p) > Maxrunes)
die("dictionary candidate too long: %s:%d", path, lineno);
if(e == line+len)
break;
}
sinit(&key, line, tab - line);
hmapset(&h, &key, tab+1, len - (tab - line) - 1);
free(line);