--- ttmkfdir-3.0.9/encoding.l.sopwith 2004-08-16 23:19:43.240502008 -0400 +++ ttmkfdir-3.0.9/encoding.l 2004-08-16 23:30:25.554857601 -0400 @@ -98,6 +98,7 @@ UNDEFINE{WHITESPACES}{NUMBER}({WHITESPACES}{NUMBER})? { char *startptr = strip_first (yytext); char *endptr; + long msize = cur_map->size(); int i1 = std::strtol (startptr, &endptr, 0); startptr = endptr; @@ -107,15 +108,16 @@ if (startptr == endptr) { i2 = i1; } - + /* now mark all the unassigned codes */ - for (long i = i1; i <= i2; i++) { + for (long i = i1; i <= i2 && i < msize; i++) { (*cur_map)[i] = -1; } } {NUMBER}({WHITESPACES}{NUMBER}){0,2} { - int numbers[3], i = 0, start_range, end_range, target, res; + int numbers[3], target, res; + unsigned int i = 0, start_range, end_range; char *startptr; char *endptr = yytext; --- ttmkfdir-3.0.9/encoding.cpp.sopwith 2004-08-16 23:21:25.705652813 -0400 +++ ttmkfdir-3.0.9/encoding.cpp 2004-08-16 23:30:25.554857601 -0400 @@ -121,7 +121,7 @@ NumericMapping *m = new NumericMapping (size, b->mapdata.platform, b->mapdata.encoding); - for (int i = 0; i < size; i++) + for (unsigned int i = 0; i < size; i++) (*m)[i] = b->mapdata.mappingtable[i]; AddMapping (m); --- ttmkfdir-3.0.9/ttf.cpp.sopwith 2004-08-16 23:33:37.767153780 -0400 +++ ttmkfdir-3.0.9/ttf.cpp 2004-08-16 23:39:37.399443682 -0400 @@ -51,20 +51,26 @@ bool Face::MappingPresent (int cmapidx, NumericMapping *m, int enc_size, int start_code, bool enc_comp) { - int idx, missing = 0; + int idx; + unsigned int missing = 0, bail_at, msize; + FT_Set_Charmap (face, face->charmaps[cmapidx]); - for (unsigned int i = start_code; i < m->size (); i++) { + msize = m->size(); + if (enc_size <= 256) { + bail_at = int (cmdline::instance()->option ("max-missing")); + } else { + bail_at = ((int (cmdline::instance()->option ("max-missing-percentage")) & enc_comp)*enc_size)/100; + } + + for (unsigned int i = start_code; i < msize && missing < bail_at; i++) { if ((*m)[i] < 0) continue; if ((idx = FT_Get_Char_Index (face, (*m)[i])) == 0) missing++; } - if (enc_size <= 256) { - return (missing <= int (cmdline::instance()->option ("max-missing"))); - } else { - return ((100 * missing/enc_size) <= int (cmdline::instance()->option ("max-missing-percentage")) & enc_comp); - } + + return missing < bail_at; } Face::Face (const std::string &filename) --- ttmkfdir-3.0.9/directory.cpp.sopwith 2004-08-16 23:41:25.354909446 -0400 +++ ttmkfdir-3.0.9/directory.cpp 2004-08-16 23:53:38.173352273 -0400 @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include #include "directory.h" @@ -37,19 +39,24 @@ bool ttfdirectory::select (const char *name) const { - int len; + int fd; + unsigned int n; struct stat buf; + char sigdata[8]; + char TTsig[] = "\000\001\000\000\000", OTsig[] = "OTTO"; /* must be a regular file */ if (::stat (name, &buf) || !(S_ISREG (buf.st_mode))) { return false; } - - /* we make the decision by the extension of the file name */ - return (((len = strlen (name)) > 4) && - (name[len - 4] == '.') && - (std::toupper(name[len - 3]) == 'T') && - (std::toupper(name[len - 2]) == 'T') && - ((std::toupper(name[len - 1]) == 'F') || - (std::toupper(name[len - 1]) == 'C'))); + + fd = ::open(name, O_RDONLY); + if (fd < 0) return false; + n = read(fd, sigdata, sizeof(sigdata)); + close(fd); + if (n < sizeof(sigdata)) + return false; + + return (!memcmp(sigdata, TTsig, 5) + || !memcmp(sigdata, OTsig, 4)); }