Fixed possible string overflow in StringEncoder