]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add test for macOS metadata reading in tar archives 2636/head
authorZhaofeng Li <hello@zhaofeng.li>
Sat, 24 May 2025 22:40:08 +0000 (16:40 -0600)
committerZhaofeng Li <hello@zhaofeng.li>
Sat, 24 May 2025 22:42:26 +0000 (16:42 -0600)
Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_format_tar_mac_metadata.c [new file with mode: 0644]
libarchive/test/test_read_format_tar_mac_metadata_1.tar.uu [new file with mode: 0644]

index 74cb6e14b6092e58bba75b2bfffd2817761c71ef..d159f29708469ab34da7fb1725c53b968bbeaf7c 100644 (file)
@@ -531,6 +531,7 @@ libarchive_test_SOURCES= \
        libarchive/test/test_read_format_tar_empty_with_gnulabel.c \
        libarchive/test/test_read_format_tar_filename.c \
        libarchive/test/test_read_format_tar_invalid_pax_size.c \
+       libarchive/test/test_read_format_tar_mac_metadata.c \
        libarchive/test/test_read_format_tar_pax_g_large.c \
        libarchive/test/test_read_format_tar_pax_large_attr.c \
        libarchive/test/test_read_format_tbz.c \
@@ -975,6 +976,7 @@ libarchive_test_EXTRA_DIST=\
        libarchive/test/test_read_format_tar_empty_pax.tar.Z.uu \
        libarchive/test/test_read_format_tar_filename_koi8r.tar.Z.uu \
        libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu \
+       libarchive/test/test_read_format_tar_mac_metadata_1.tar.uu \
        libarchive/test/test_read_format_tar_pax_g_large.tar.uu \
        libarchive/test/test_read_format_tar_pax_large_attr.tar.Z.uu \
        libarchive/test/test_read_format_ustar_filename_cp866.tar.Z.uu \
index ffdb5b4ef7c52a5b65f3d67e129941870e65c0b7..2fa8b01c86486b712dc466c60b935d785183921b 100644 (file)
@@ -174,6 +174,7 @@ IF(ENABLE_TEST)
     test_read_format_tar_empty_pax.c
     test_read_format_tar_filename.c
     test_read_format_tar_invalid_pax_size.c
+    test_read_format_tar_mac_metadata.c
     test_read_format_tar_pax_g_large.c
     test_read_format_tar_pax_large_attr.c
     test_read_format_tbz.c
diff --git a/libarchive/test/test_read_format_tar_mac_metadata.c b/libarchive/test/test_read_format_tar_mac_metadata.c
new file mode 100644 (file)
index 0000000..b4745a2
--- /dev/null
@@ -0,0 +1,85 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Zhaofeng Li
+ * All rights reserved.
+ */
+#include "test.h"
+
+DEFINE_TEST(test_read_format_tar_mac_metadata)
+{
+       /*
+        This test tar file is crafted with two files in a specific order:
+
+        1. A ._-prefixed file with pax header containing the path attribute.
+        2. A file with a pax header but without the path attribute.
+
+        It's designed to trigger the case encountered in:
+        <https://github.com/libarchive/libarchive/pull/2636>
+
+        GNU tar is required to reproduce this tar file:
+
+        ```sh
+        NAME1="._101_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+        NAME2="goodname"
+        OUT="test_read_format_tar_mac_metadata_1.tar"
+
+        echo "content of badname" >"${NAME1}"
+        echo "content of goodname" >"${NAME2}"
+
+        rm -f "${OUT}"
+        gnutar \
+               --mtime="@0" \
+               --owner=0 --group=0 --numeric-owner \
+               --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,ctime:=0,foo:=bar \
+               --format=pax \
+               -cf "${OUT}" \
+               "${NAME1}" \
+               "${NAME2}"
+        uuencode "${OUT}" "${OUT}" >"${OUT}.uu"
+
+        sha256sum "${OUT}"
+        sha256sum "${OUT}.uu"
+        ```
+       */
+       const char *refname = "test_read_format_tar_mac_metadata_1.tar";
+       char *p;
+       size_t s;
+       struct archive *a;
+       struct archive_entry *ae;
+
+       /*
+        * This is not a valid AppleDouble metadata file. It is merely to test that
+        * the correct bytes are read.
+        */
+       const unsigned char appledouble[] = {
+               0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x62,
+               0x61, 0x64, 0x6e, 0x61, 0x6d, 0x65, 0x0a
+       };
+
+       extract_reference_file(refname);
+       p = slurpfile(&s, "%s", refname);
+
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_tar(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_set_option(a, "tar", "mac-ext", "1"));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
+
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+
+       /* Correct name and metadata bytes */
+       assertEqualString("goodname", archive_entry_pathname(ae));
+
+       const void *metadata = archive_entry_mac_metadata(ae, &s);
+       if (assert(metadata != NULL)) {
+               assertEqualMem(metadata, appledouble,
+                       sizeof(appledouble));
+       }
+
+       /* ... and nothing else */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+
+       free(p);
+}
diff --git a/libarchive/test/test_read_format_tar_mac_metadata_1.tar.uu b/libarchive/test/test_read_format_tar_mac_metadata_1.tar.uu
new file mode 100644 (file)
index 0000000..20b2cf5
--- /dev/null
@@ -0,0 +1,231 @@
+begin 644 test_read_format_tar_mac_metadata_1.tar
+M+B]087A(96%D97)S+RY?,3`Q7V%A86%A86%A86%A86%A86%A86%A86%A86%A
+M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A
+M86%A86%A86%A83`P,#`V-#0`,#`P,#`P,``P,#`P,#`P`#`P,#`P,#`P,C(P
+M`#`P,#`P,#`P,#`P`#`S,#,Q,0`@>```````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,```````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````Q,3$@<&%T:#TN7S$P,5]A86%A86%A86%A86%A
+M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A
+M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A80HQ,2!F;V\]
+M8F%R"C$Q(&-T:6UE/3`*,3$@871I;64],`H`````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````"Y?,3`Q7V%A86%A
+M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A
+M86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86%A86$P
+M,#`P-C0T`#`P,#`P,#``,#`P,#`P,``P,#`P,#`P,#`R,P`P,#`P,#`P,#`P
+M,``P,S`S-S8`(#``````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````=7-T87(`,#``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````8V]N=&5N="!O9B!B861N86UE"@``````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M```````````````````````````````N+U!A>$AE861E<G,O9V]O9&YA;64`
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````,#`P,#8T-``P,#`P
+M,#`P`#`P,#`P,#``,#`P,#`P,#`P-#$`,#`P,#`P,#`P,#``,#$Q-S0U`"!X
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````'5S=&%R`#`P````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````````````#$Q(&9O
+M;SUB87(*,3$@8W1I;64],`HQ,2!A=&EM93TP"@``````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````9V]O9&YA;64`````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````#`P,#`V-#0`,#`P,#`P,``P,#`P,#`P
+M`#`P,#`P,#`P,#(T`#`P,#`P,#`P,#`P`#`P-S0U-0`@,```````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````````````!U
+M<W1A<@`P,```````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````!C;VYT96YT(&]F(&=O;V1N
+M86UE"@``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+9````````````````````````````````````
+`
+end