encoding: Readd some UTF-8 validation to encoders This isn't strictly needed but avoids generating invalid UTF-16 and unsigned integer overflows.