@@ -27,25 +27,25 @@ #import "OFMutableString.h" #import "OFExceptions.h" #import "OFMacros.h" #import "asprintf.h" - -extern const of_unichar_t* const of_unicode_upper_table[0x1100]; -extern const of_unichar_t* const of_unicode_lower_table[0x1100]; +#import "unicode.h" static void apply_table(id self, Class isa, char **string, unsigned int *length, - BOOL is_utf8, const of_unichar_t* const table[]) + BOOL is_utf8, const of_unichar_t* const table[], const size_t table_size) { of_unichar_t c, tc; of_unichar_t *ustr; size_t ulen, nlen; size_t i, j, d; char *nstr; if (!is_utf8) { + assert(table_size >= 1); + uint8_t *p = (uint8_t*)*string + *length; uint8_t t; while (--p >= (uint8_t*)*string) if ((t = table[0][*p]) != 0) @@ -67,11 +67,14 @@ if (c == OF_INVALID_UNICHAR || c > 0x10FFFF) { [self freeMemory: ustr]; @throw [OFInvalidEncodingException newWithClass: isa]; } - if ((tc = table[c >> 8][c & 0xFF]) == 0) + if (c >> 8 < table_size) { + if ((tc = table[c >> 8][c & 0xFF]) == 0) + tc = c; + } else tc = c; ustr[j++] = tc; if (tc < 0x80) nlen++; @@ -371,19 +374,19 @@ } - upper { apply_table(self, isa, &string, &length, is_utf8, - of_unicode_upper_table); + of_unicode_upper_table, OF_UNICODE_UPPER_TABLE_SIZE); return self; } - lower { apply_table(self, isa, &string, &length, is_utf8, - of_unicode_lower_table); + of_unicode_lower_table, OF_UNICODE_LOWER_TABLE_SIZE); return self; } - removeCharactersFromIndex: (size_t)start