]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
LHA reader UTF-16: Encode directory separator with archive_le16enc()
authorMartin Matuska <martin@matuska.org>
Thu, 9 Jan 2020 09:51:34 +0000 (10:51 +0100)
committerMartin Matuska <martin@matuska.org>
Thu, 9 Jan 2020 09:52:44 +0000 (10:52 +0100)
Wrap to 80 characters.
Fixes #1307

libarchive/archive_read_support_format_lha.c

index f03377592b11288a002962de5b712a8dfab29ae0..aa115f87dceccdbe7f5670239c796f3398e7d130 100644 (file)
@@ -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: