Subject: Avoid over-trimming UCS16 text, and ending up losing the last character Origin: FILE5_35-16-g6d90cbff Upstream-Author: Christos Zoulas Date: Tue Nov 27 17:34:32 2018 +0000 --- a/src/ascmagic.c +++ b/src/ascmagic.c @@ -81,6 +81,12 @@ bb = *b; bb.flen = trim_nuls(CAST(const unsigned char *, b->fbuf), b->flen); + /* + * Avoid trimming at an odd byte if the original buffer was evenly + * sized; this avoids losing the last character on UTF-16 LE text + */ + if ((bb.flen & 1) && !(b->flen & 1)) + bb.flen++; /* If file doesn't look like any sort of text, give up. */ if (file_encoding(ms, &bb, &ubuf, &ulen, &code, &code_mime,