]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
archive_entry_pathname() tries UTF-8 if MBS returns EILSEQ 1772/head
authorJohn Reiser <jreiser@BitWagon.com>
Fri, 26 Aug 2022 16:51:19 +0000 (09:51 -0700)
committerJohn Reiser <jreiser@BitWagon.com>
Fri, 26 Aug 2022 16:51:19 +0000 (09:51 -0700)
For better pathname portability across OS, in particular Windows to Linux.
Original bug: unrar in https://bugzilla.redhat.com/show_bug.cgi?id=2120926
        modified:   libarchive/archive_entry.c

libarchive/archive_entry.c

index ca7a4bdb50e7646c76b4025751176193dacd1537..ae6dc333619add944ca1c61788f57e18a53efc5b 100644 (file)
@@ -568,6 +568,13 @@ archive_entry_nlink(struct archive_entry *entry)
        return (entry->ae_stat.aest_nlink);
 }
 
+/* Instead, our caller could have chosen a specific encoding
+ * (archive_mstring_get_mbs, archive_mstring_get_utf8,
+ * archive_mstring_get_wcs).  So we should try multiple
+ * encodings.  Try mbs first because of history, even though
+ * utf8 might be better for pathname portability.
+ * Also omit wcs because of type mismatch (char * versus wchar *)
+ */
 const char *
 archive_entry_pathname(struct archive_entry *entry)
 {
@@ -575,6 +582,13 @@ archive_entry_pathname(struct archive_entry *entry)
        if (archive_mstring_get_mbs(
            entry->archive, &entry->ae_pathname, &p) == 0)
                return (p);
+#if HAVE_EILSEQ  /*{*/
+    if (errno == EILSEQ) {
+           if (archive_mstring_get_utf8(
+               entry->archive, &entry->ae_pathname, &p) == 0)
+                   return (p);
+    }
+#endif  /*}*/
        if (errno == ENOMEM)
                __archive_errx(1, "No memory");
        return (NULL);