]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix tests on Windows (#2091)
authorDuncan Horn <40036384+dunhor@users.noreply.github.com>
Sat, 23 Mar 2024 17:13:49 +0000 (10:13 -0700)
committerGitHub <noreply@github.com>
Sat, 23 Mar 2024 17:13:49 +0000 (18:13 +0100)
For the most part, a good number of
failing tests are failing because they make the assumption that archive
contents are read as utf-8 by default, which is not true for Windows,
which assumes OEM code page by default.

.gitignore
libarchive/archive_read_disk_windows.c
libarchive/archive_string.c
libarchive/test/test_read_format_cpio_filename.c
libarchive/test/test_read_format_rar.c
libarchive/test/test_read_format_zip_filename.c
libarchive/test/test_sparse_basic.c
libarchive/test/test_zip_filename_encoding.c

index 359b652368d09923d10bcd08306e587bba0c2870..8dc637ee132d800fe686e2fc9218bb6ffe4f1734 100644 (file)
@@ -47,6 +47,7 @@ CMakeCache.txt
 CMakeFiles/
 DartConfiguration.tcl
 cmake.tmp/
+.vscode/
 
 doc/html/*.html
 doc/man/*.1
@@ -74,3 +75,5 @@ test-suite.log
 
 .sw?
 .*.sw?
+
+*.pdb
index b42b6bcad8374664a65d31419712aa9a568f6cc6..6b551f4bb0a7e7b0b2e0c2860867ac9fa81ab652 100644 (file)
@@ -2438,6 +2438,7 @@ archive_read_disk_entry_from_file(struct archive *_a,
                return (ARCHIVE_OK);
        }
 
+       r = ARCHIVE_OK;
        if ((a->flags & ARCHIVE_READDISK_NO_SPARSE) == 0) {
                r = setup_sparse_from_disk(a, entry, h);
                if (fd < 0)
index 17cfd384cd58a40411b7e57b0993371c8df01f21..f39677ad7a261a37e4c8f8f0c64bde93a326280f 100644 (file)
@@ -552,6 +552,8 @@ archive_wstring_append_from_mbs_in_codepage(struct archive_wstring *dest,
                } else
                        mbflag = MB_PRECOMPOSED;
 
+               mbflag |= MB_ERR_INVALID_CHARS;
+
                buffsize = dest->length + length + 1;
                do {
                        /* Allocate memory for WCS. */
@@ -1526,7 +1528,7 @@ get_current_codepage(void)
        p = strrchr(locale, '.');
        if (p == NULL)
                return (GetACP());
-       if (strcmp(p+1, "utf8") == 0)
+       if ((strcmp(p+1, "utf8") == 0) || (strcmp(p+1, "UTF-8") == 0))
                return CP_UTF8;
        cp = my_atoi(p+1);
        if ((int)cp <= 0)
index fe484282a48d5cf2851148433700187d4db55939..c5aa9a7f52a0fda5d6422af71a96f044b3b4ac6c 100644 (file)
@@ -136,6 +136,11 @@ cleanup:
 
 DEFINE_TEST(test_read_format_cpio_filename_UTF8_UTF8_jp)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       /* Since we explicitly DON'T set hdrcharset=UTF-8 below */
+       skipping("Windows defaults to OEMCP, not UTF-8");
+       return;
+#else
        const char *refname = "test_read_format_cpio_filename_utf8_jp.cpio";
        struct archive *a;
        struct archive_entry *ae;
@@ -179,6 +184,7 @@ DEFINE_TEST(test_read_format_cpio_filename_UTF8_UTF8_jp)
        /* Close the archive. */
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+#endif
 }
 
 DEFINE_TEST(test_read_format_cpio_filename_CP866_KOI8R)
@@ -499,6 +505,11 @@ cleanup:
 
 DEFINE_TEST(test_read_format_cpio_filename_UTF8_UTF8_ru)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       /* Since we explicitly DON'T set hdrcharset=UTF-8 below */
+       skipping("Windows defaults to OEMCP, not UTF-8");
+       return;
+#else
        const char *refname = "test_read_format_cpio_filename_utf8_ru.cpio";
        struct archive *a;
        struct archive_entry *ae;
@@ -541,6 +552,7 @@ DEFINE_TEST(test_read_format_cpio_filename_UTF8_UTF8_ru)
        /* Close the archive. */
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+#endif
 }
 
 DEFINE_TEST(test_read_format_cpio_filename_eucJP_CP932)
index ad7c307cc15478d668e51f654dafaeea7c61aae9..dce567af48a907401a4cd6eed4261c9ef1bcb04a 100644 (file)
@@ -214,6 +214,14 @@ DEFINE_TEST(test_read_format_rar_unicode_UTF8)
   assert((a = archive_read_new()) != NULL);
   assertA(0 == archive_read_support_filter_all(a));
   assertA(0 == archive_read_support_format_all(a));
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  /* Windows will use OEMCP as default, but the file is UTF-8. */
+  if (ARCHIVE_OK != archive_read_set_options(a, "rar:hdrcharset=UTF-8")) {
+       skipping("This system cannot read input as UTF-8.");
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+       return;
+  }
+#endif
   assertA(0 == archive_read_open_filename(a, reffile, 10240));
 
   /* First header. */
index c191cfa9cb254ddd71cb131eef209f04eff3a9ee..b673344738be751100890e4f5e2358795d3cd6fb 100644 (file)
@@ -1177,6 +1177,11 @@ DEFINE_TEST(test_read_format_zip_filename_KOI8R_UTF8_2)
 next_test:
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 
+       /*
+        * By default, Windows will create an sconv_default object, which will
+        * interpret filenames as OEMCP
+        */
+#if !defined(_WIN32) || defined(__CYGWIN__)
        /*
         * Read filename in en_US.UTF-8 without "hdrcharset=KOI8-R" option.
         * The filename we can properly read is only second file.
@@ -1220,4 +1225,5 @@ next_test:
        /* Close the archive. */
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+#endif
 }
index 0bb272b61203ff4e8d8adfea2134d83e4cad9e37..0350df1e9f27638eb7c798eb0a7867c487f62fc0 100644 (file)
@@ -120,7 +120,7 @@ create_sparse_file(const char *path, const struct sparse *s)
        memset(buff, ' ', sizeof(buff));
 
        handle = CreateFileA(path, GENERIC_WRITE, 0,
-           NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
+           NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
            NULL);
        assert(handle != INVALID_HANDLE_VALUE);
        assert(DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0,
index e4a15a1a755ff0290f44bd930d0f599f57ebe1fe..448fb9b1d4ef370baa926c740f1bfb5ad7ec0eff 100644 (file)
@@ -70,7 +70,9 @@ DEFINE_TEST(test_zip_filename_encoding_UTF8)
        /*
         * Verify that UTF-8 filenames are correctly stored without
         * hdrcharset=UTF-8 option.
+        * Skip on Windows where we default to OEMCP
         */
+#if !defined(_WIN32) || defined(__CYGWIN__)
        a = archive_write_new();
        assertEqualInt(ARCHIVE_OK, archive_write_set_format_zip(a));
        assertEqualInt(ARCHIVE_OK,
@@ -89,6 +91,7 @@ DEFINE_TEST(test_zip_filename_encoding_UTF8)
         * which indicates the filename charset is UTF-8. */
        assertEqualInt(0x08, buff[7]);
        assertEqualMem(buff + 30, "\xD0\xBF\xD1\x80\xD0\xB8", 6);
+#endif
 
        /*
         * Verify that A bit 11 of general purpose flag is not set