cherry-pick.FILE5_35-16-g6d90cbff.avoid-over-trimming-ucs16-text-and-ending-up-losing-the-last-character.patch 734 B

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