fix a possible crash due to encoding