From: Martin Matuska Date: Thu, 9 Jan 2020 09:51:34 +0000 (+0100) Subject: LHA reader UTF-16: Encode directory separator with archive_le16enc() X-Git-Tag: v3.4.2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c34952a78284b505c88546a3d0a056182bf1c0da;p=thirdparty%2Flibarchive.git LHA reader UTF-16: Encode directory separator with archive_le16enc() Wrap to 80 characters. Fixes #1307 --- diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index f03377592..aa115f87d 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -1246,8 +1246,9 @@ lha_read_file_extended_header(struct archive_read *a, struct lha *lha, archive_array_append(&lha->filename, (const char *)extdheader, datasize); /* Setup a string conversion for a filename. */ - lha->sconv_fname = archive_string_conversion_from_charset( - &a->archive, "UTF-16LE", 1); + lha->sconv_fname = + archive_string_conversion_from_charset(&a->archive, + "UTF-16LE", 1); if (lha->sconv_fname == NULL) return (ARCHIVE_FATAL); break; @@ -1273,15 +1274,18 @@ lha_read_file_extended_header(struct archive_read *a, struct lha *lha, break; case EXT_UTF16_DIRECTORY: /* UTF-16 characters take always 2 or 4 bytes */ - if (datasize == 0 || (datasize & 1) || extdheader[0] == '\0') + if (datasize == 0 || (datasize & 1) || + extdheader[0] == '\0') { /* no directory name data. exit this case. */ goto invalid; + } archive_string_empty(&lha->dirname); archive_array_append(&lha->dirname, (const char *)extdheader, datasize); - lha->sconv_dir = archive_string_conversion_from_charset( - &a->archive, "UTF-16LE", 1); + lha->sconv_dir = + archive_string_conversion_from_charset(&a->archive, + "UTF-16LE", 1); if (lha->sconv_dir == NULL) return (ARCHIVE_FATAL); else { @@ -1289,17 +1293,22 @@ lha_read_file_extended_header(struct archive_read *a, struct lha *lha, * Convert directory delimiter from 0xFFFF * to '/' for local system. */ - uint16_t dirSep = '/'; /* UTF-16LE */ + const uint16_t dirSep = '/'; /* UTF-16LE */ /* UTF-16LE character */ - uint16_t *utf16name = (uint16_t *)lha->dirname.s; + uint16_t *utf16name = + (uint16_t *)lha->dirname.s; for (i = 0; i < lha->dirname.length / 2; i++) { - if (utf16name[i] == 0xFFFF) - utf16name[i] = dirSep; + if (utf16name[i] == 0xFFFF) { + archive_le16enc(utf16name + i, + dirSep); + } } /* Is last character directory separator? */ - if (utf16name[lha->dirname.length / 2 - 1] != dirSep) + if (utf16name[lha->dirname.length / 2 - 1] != + dirSep) { /* invalid directory data */ goto invalid; + } } break; case EXT_DOS_ATTR: