fix buffer overrun while converting charsets