]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge pull request #2477 from jrtc27/safe-dir-over-reg
authorMartin Matuška <martin@matuska.de>
Wed, 10 Sep 2025 08:40:44 +0000 (10:40 +0200)
committerMartin Matuska <martin@matuska.de>
Tue, 23 Sep 2025 20:59:25 +0000 (22:59 +0200)
Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES

(cherry picked from commit 52db141eced88e0aa43f8656211af8ed74c6c280)

libarchive/archive_write_disk_posix.c
tar/test/test_option_safe_writes.c

index d8ea0cc3fb9bb76851981c606a47ff69403a845c..6fcf3929b5cb69091ab8cdf080af8c3afcb14b2c 100644 (file)
@@ -2204,7 +2204,7 @@ restore_entry(struct archive_write_disk *a)
                                (void)clear_nochange_fflags(a);
 
                        if ((a->flags & ARCHIVE_EXTRACT_SAFE_WRITES) &&
-                           S_ISREG(a->st.st_mode)) {
+                           S_ISREG(a->mode)) {
                                /* Use a temporary file to extract */
                                if ((a->fd = la_mktemp(a)) == -1) {
                                        archive_set_error(&a->archive, errno,
index b88479bc5f35a929b9ce4c1f7f51c9a3df362866..d30b9a7459278ebd35921cf6000d85af64e14107 100644 (file)
@@ -16,11 +16,12 @@ DEFINE_TEST(test_option_safe_writes)
        assertMakeFile("d", 0644, "c");
        assertMakeFile("fs", 0644, "d");
        assertMakeFile("ds", 0644, "e");
+       assertMakeDir("fd", 0755);
        assertEqualInt(0, chdir(".."));
 
        /* Tar files up */
        assertEqualInt(0,
-           systemf("%s -c -C in -f t.tar f fh d fs ds "
+           systemf("%s -c -C in -f t.tar f fh d fs ds fd "
            ">pack.out 2>pack.err", testprog));
 
         /* Verify that nothing went to stdout or stderr. */
@@ -32,6 +33,7 @@ DEFINE_TEST(test_option_safe_writes)
        assertEqualInt(0, chdir("out"));
        assertMakeFile("f", 0644, "a");
        assertMakeHardlink("fh", "f");
+       assertMakeFile("fd", 0644, "b");
        assertMakeDir("d", 0755);
        if (canSymlink()) {
                assertMakeSymlink("fs", "f", 0);
@@ -55,4 +57,5 @@ DEFINE_TEST(test_option_safe_writes)
        assertTextFileContents("c","d");
        assertTextFileContents("d","fs");
        assertTextFileContents("e","ds");
+       assertIsDir("fd", 0755);
 }