Properly handle invalid UTF8 output (fixes #15).