]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
unzip: Add symlink tests 3176/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 22 Jun 2026 20:29:11 +0000 (22:29 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 23 Jun 2026 18:12:26 +0000 (20:12 +0200)
Verify that symlink creations and overwriting works, i.e. that dangling
symlinks are properly overwritten.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Makefile.am
unzip/test/CMakeLists.txt
unzip/test/test_symlink.c [new file with mode: 0644]
unzip/test/test_symlink_1.zip.uu [new file with mode: 0644]
unzip/test/test_symlink_2.zip.uu [new file with mode: 0644]

index f136c3a1d0960981e10f82852e2fe161b1c5174a..8ac57db2126ef0c2ce0dd146caa4210e288b9f71 100644 (file)
@@ -1710,6 +1710,7 @@ bsdunzip_test_SOURCES= \
        unzip/test/test_n.c \
        unzip/test/test_o.c \
        unzip/test/test_q.c \
+       unzip/test/test_symlink.c \
        unzip/test/test_t.c \
        unzip/test/test_t_bad.c \
        unzip/test/test_u.c \
@@ -1746,6 +1747,8 @@ bsdunzip_test_EXTRA_DIST= \
        unzip/test/test_f_new.zip.uu \
        unzip/test/test_f_old.zip.uu \
        unzip/test/test_singlefile.zip.uu \
+       unzip/test/test_symlink_1.zip.uu \
+       unzip/test/test_symlink_2.zip.uu \
        unzip/test/test_t_bad.zip.uu \
        unzip/test/test_u_new.zip.uu \
        unzip/test/test_u_old.zip.uu \
index 55d4d4b95c6331ab494b53debc1b2311cfcba8e8..0aee8a173da8cf91532cdfadd7dce6d8cf5e2b01 100644 (file)
@@ -15,6 +15,7 @@ IF(ENABLE_UNZIP AND ENABLE_TEST)
     test_glob.c
     test_not_exist.c
     test_singlefile.c
+    test_symlink.c
     test_C.c
     test_p.c
     test_d.c
diff --git a/unzip/test/test_symlink.c b/unzip/test/test_symlink.c
new file mode 100644 (file)
index 0000000..3ee2997
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Tobias Stoeckmann
+ * All rights reserved.
+ */
+#include "test.h"
+
+/* Test symlinks */
+DEFINE_TEST(test_symlink)
+{
+       const char *reffile1 = "test_symlink_1.zip";
+       const char *reffile2 = "test_symlink_2.zip";
+       int r;
+
+       if (!canSymlink()) {
+               skipping("System cannot create symlinks.");
+               return;
+       }
+
+       extract_reference_file(reffile1);
+       extract_reference_file(reffile2);
+
+       /* Extract first archive */
+       r = systemf("%s %s >test.out 2>test.err", testprog, reffile1);
+       assertEqualInt(0, r);
+       assertNonEmptyFile("test.out");
+       assertNonEmptyFile("test.err");
+       assertIsDir("dir", 0755);
+       assertIsSymlink("dlink", "dir", 1);
+       assertIsReg("file.txt", 0644);
+       assertIsSymlink("flink", "file.txt", 0);
+       assertFileNotExists("link.insecure");
+
+       /* Create dangling symlinks by deleting targets */
+       rmdir("dir");
+       unlink("file.txt");
+       assertFileNotExists("dir");
+       assertFileNotExists("file.txt");
+       assertIsSymlink("dlink", "dir", 1);
+       assertIsSymlink("flink", "file.txt", 0);
+
+       /* Extract second archive, overwriting dangling symlinks */
+       r = systemf("%s -o %s >test.out 2>test.err", testprog, reffile2);
+       assertEqualInt(0, r);
+       assertEmptyFile("test.out");
+       assertEmptyFile("test.err");
+       assertFileNotExists("dir");
+       assertIsDir("dlink", 0755);
+       assertTextFileContents("hello world\n", "dlink/file.txt");
+       assertIsReg("flink", 0644);
+}
diff --git a/unzip/test/test_symlink_1.zip.uu b/unzip/test/test_symlink_1.zip.uu
new file mode 100644 (file)
index 0000000..60b9a69
--- /dev/null
@@ -0,0 +1,21 @@
+begin 644 test_symlink_1.zip
+M4$L#!!0``````)&NUEP````````````````$`"``9&ER+W5X"P`!!.@#```$
+MZ`,``%54#0`'@I(Y:H*2.6J"DCEJ4$L#!!0``````)"NUEP0>JNZ`P````,`
+M```%`"``9&QI;FMU>`L``03H`P``!.@#``!55`T`!X"2.6J`DCEJ@)(Y:F1I
+M<E!+`P0*``@```"5KM9<````````````````"``@`&9I;&4N='AT=7@+``$$
+MZ`,```3H`P``550-``>+DCEJBY(Y:HN2.6I02P<(````````````````4$L#
+M!!0``````)>NUEPE%O?@"`````@````%`"``9FQI;FMU>`L``03H`P``!.@#
+M``!55`T`!X^2.6J/DCEJCY(Y:F9I;&4N='AT4$L#!!0``````(RNUEP&4/WP
+M"@````H````-`"``:6YS96-U<F4N;&EN:W5X"P`!!.@#```$Z`,``%54#0`'
+M>9(Y:GF2.6IYDCEJ+BXO;W5T<VED95!+`0(4`Q0``````)&NUEP`````````
+M```````$`!@```````````#M00````!D:7(O=7@+``$$Z`,```3H`P``550%
+M``&"DCEJ4$L!`A0#%```````D*[67!!ZJ[H#`````P````4`&```````````
+M`/^A0@```&1L:6YK=7@+``$$Z`,```3H`P``550%``&`DCEJ4$L!`@H#"@`(
+M````E:[67`````````````````@`&````````````*2!B````&9I;&4N='AT
+M=7@+``$$Z`,```3H`P``550%``&+DCEJ4$L!`A0#%```````EZ[67"46]^`(
+M````"`````4`&````````````/^AW@```&9L:6YK=7@+``$$Z`,```3H`P``
+M550%``&/DCEJ4$L!`A0#%```````C*[67`90_?`*````"@````T`&```````
+M`````/^A*0$``&EN<V5C=7)E+FQI;FMU>`L``03H`P``!.@#``!55`4``7F2
+8.6I02P4&``````4`!0"!`0``?@$`````
+`
+end
diff --git a/unzip/test/test_symlink_2.zip.uu b/unzip/test/test_symlink_2.zip.uu
new file mode 100644 (file)
index 0000000..1cc92d7
--- /dev/null
@@ -0,0 +1,12 @@
+begin 644 test_symlink_2.zip
+M4$L#!`H`"````,NNUEP````````````````.`"``9&QI;FLO9FEL92YT>'1U
+M>`L``03H`P``!.@#``!55`T`!^^2.6KODCEJ[Y(Y:FAE;&QO('=O<FQD"E!+
+M!P@M.PBO#`````P```!02P,$"@`(````V*[67`````````````````4`(`!F
+M;&EN:W5X"P`!!.@#```$Z`,``%54#0`'"9,Y:A>3.6H)DSEJ8V]N=&5N="!F
+M;&EN:PI02P<(%P(`(PX````.````4$L!`@H#"@`(````RZ[67"T["*\,````
+M#`````X`&````````````*2!`````&1L:6YK+V9I;&4N='AT=7@+``$$Z`,`
+M``3H`P``550%``'ODCEJ4$L!`@H#"@`(````V*[67!<"`",.````#@````4`
+M&````````````*2!:````&9L:6YK=7@+``$$Z`,```3H`P``550%``$)DSEJ
+64$L%!@`````"``(`GP```,D`````````
+`
+end