quentinmit/mosh — comment on commit 42da3c03a8d88e9f098695756186ec983e61c4cb
File:  line 0
By keithw:

Unfortunately, on OS X, mbrtowc() is not strictly Unicode/UCS conformant, in that it will happily accept an invalid UTF-8 sequence that specifies something that is not a Unicode scalar value (but is, rather, a code point in the range for UTF-16 surrogate pairs).

The bottom line is we need to fortify Parser::UTF8Parser::input() to produce a correct UTF-8 vt500 state machine (that handles invalid UTF-8 input in accordance with Unicode 6.0, section 3.9, "Best Practices for using U+FFFD") under these more liberal wide-character functions. Otherwise we will end up generating illegal UTF-8 ourselves off the other end which I don't think is okay.