Merge pull request #2477 from jrtc27/safe-dir-over-reg

Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES

(cherry picked from commit 52db141ece)
This commit is contained in:
Martin Matuška authored and Martin Matuska committed 2025-09-23 22:59:25 +02:00
1 parent 8055fbd321
commit 927dd43020
2 files changed
+5 -2

No files matched your search

+1 -1
View 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,
+4 -1
View 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);
}