]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix encoding detection on platforms with nl_langinfo() (#2030)
authorAaron Lindros <lindros.aaron@gmail.com>
Sat, 9 Dec 2023 01:50:03 +0000 (20:50 -0500)
committerGitHub <noreply@github.com>
Sat, 9 Dec 2023 01:50:03 +0000 (17:50 -0800)
libarchive relies on its host program to call setlocale() on platforms
with nl_langinfo() present in order to correctly detect the user
selected locale. This ensures that bsdunzip does so.

Makefile.am
unzip/bsdunzip.c
unzip/test/CMakeLists.txt
unzip/test/test_I.c [new file with mode: 0644]
unzip/test/test_I.zip.uu [new file with mode: 0644]

index a6b199779c387561c578210c9356fad33e54e1b3..b5ccae02ed165843d40b8dd11b7433804c67c834 100644 (file)
@@ -1522,7 +1522,8 @@ bsdunzip_test_SOURCES= \
        unzip/test/test_version.c \
        unzip/test/test_x.c \
        unzip/test/test_Z1.c \
-       unzip/test/test_P_encryption.c
+       unzip/test/test_P_encryption.c \
+       unzip/test/test_I.c
 
 bsdunzip_test_CPPFLAGS= \
        -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe \
@@ -1550,4 +1551,5 @@ bsdunzip_test_EXTRA_DIST= \
        unzip/test/test_encrypted.zip.uu \
        unzip/test/test_singlefile.zip.uu \
        unzip/test/test_t_bad.zip.uu \
+       unzip/test/test_I.zip.uu \
        unzip/test/CMakeLists.txt
index a471965197e2c2e97007b574f2807e5773e30b0a..af3fb14c36367261fc8782da39aabcfb7f082f1b 100644 (file)
@@ -57,6 +57,9 @@
 #ifdef HAVE_FNMATCH_H
 #include <fnmatch.h>
 #endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
 #ifdef HAVE_STDARG_H
 #include <stdarg.h>
 #endif
@@ -1210,6 +1213,11 @@ main(int argc, char *argv[])
 
        lafe_setprogname(*argv, "bsdunzip");
 
+#if HAVE_SETLOCALE
+       if (setlocale(LC_ALL, "") == NULL)
+               lafe_warnc(0, "Failed to set default locale");
+#endif
+
        if (isatty(STDOUT_FILENO))
                tty = 1;
 
index 75ca0ee829be0a6c29a3da50124050b9f38cf564..f269c25f85e6d88ccd356703db268a28f6ec3fbc 100644 (file)
@@ -28,6 +28,7 @@ IF(ENABLE_UNZIP AND ENABLE_TEST)
     test_x.c
     test_Z1.c
     test_P_encryption.c
+    test_I.c
   )
 
   #
diff --git a/unzip/test/test_I.c b/unzip/test/test_I.c
new file mode 100644 (file)
index 0000000..a6bad85
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2023 Aaron Lindros
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer
+ *    in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+
+/* Test I arg - file name encoding */
+DEFINE_TEST(test_I)
+{
+       const char *reffile = "test_I.zip";
+       int r;
+
+       extract_reference_file(reffile);
+       r = systemf("%s -I UTF-8 %s >test.out 2>test.err", testprog, reffile);
+       assertEqualInt(0, r);
+       assertNonEmptyFile("test.out");
+       assertEmptyFile("test.err");
+
+       assertTextFileContents("Hello, World!\n", "Γειά σου Κόσμε.txt");
+}
diff --git a/unzip/test/test_I.zip.uu b/unzip/test/test_I.zip.uu
new file mode 100644 (file)
index 0000000..8a1e7af
--- /dev/null
@@ -0,0 +1,8 @@
+begin 644 test_I.zip
+M4$L#!`H```@``&@)AU>$GNBT#@````X````>`!P`SI/.M<ZYSJP@SX/.O\^%
+M(,Z:SXS/@\Z\SK4N='AT550)``,#8G%E"6)Q975X"P`!!.@#```$Z`,``$AE
+M;&QO+"!7;W)L9"$*4$L!`AX#"@``"```:`F'5X2>Z+0.````#@```!X`&```
+M`````````*2!`````,Z3SK7.N<ZL(,^#SK_/A2#.FL^,SX/.O,ZU+G1X=%54
+L!0`#`V)Q975X"P`!!.@#```$Z`,``%!+!08``````0`!`&0```!F````````
+`
+end