File 0002-LHA-reader-UTF-16-Encode-directory-separator-with-ar.patch of Package libarchive

From 2a1cad86378452f24aeeb55d1a64b70bfe136d0c Mon Sep 17 00:00:00 2001
From: Martin Matuska <martin@matuska.org>
Date: Thu, 9 Jan 2020 10:51:34 +0100
Subject: [PATCH 2/3] LHA reader UTF-16: Encode directory separator with
 archive_le16enc()

Wrap to 80 characters.
Fixes #1307
---
 libarchive/archive_read_support_format_lha.c | 29 +++++++++++++-------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c
index f033775..aa115f8 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:
-- 
2.25.0
openSUSE Build Service is sponsored by