I haven't tested this yet, but if anything, I think the correct patch might be this (warning, I'm not an experienced busybox contributor):

diff --git a/archival/libarchive/data_extract_all.c b/archival/libarchive/data_e
xtract_all.c
index 8a69711c1..288715293 100644
--- a/archival/libarchive/data_extract_all.c
+++ b/archival/libarchive/data_extract_all.c
@@ -143,9 +143,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_ha
ndle)
        case S_IFREG: {
                /* Regular file */
                char *dst_nameN;
                int flags = O_WRONLY | O_CREAT | O_EXCL;
                if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
-                       flags = O_WRONLY | O_CREAT | O_TRUNC;
+                       flags = O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW;
                dst_nameN = dst_name;
 #ifdef ARCHIVE_REPLACE_VIA_RENAME
                if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)

I don't think adding O_EXCL is correct, like suggested here:

On 8/5/25 3:05 PM, yuma wrote:
> Suggested patch (one-liner)
> ----------------------------------------------------------------------
> @@
> -  flags = O_WRONLY | O_CREAT | O_TRUNC;
> +  flags = O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_EXCL;
> @@
>     dst_fd = xopen3(dst_nameN, flags, file_header->mode);
>

Since I think ARCHIVE_O_TRUNC is meant to be used when the file is re-used and not re-created, hence it's not previously unlinked and may already exist.

But it might not be a bug, here's why:
======================================

However, I can see some people wanting to intentionally extract an archive with --overwrite that writes into links. Since to avoid that, it seems like omitting --overwrite is enough:

In overall, I find the option --overwrite at best not documented very well, since the naming kind of suggests that if --overwrite isn't specified then -k would be the default, which doesn't seem to be the case.

Apparently, it's possible to either 1. run with -k and keep old files, 2. run with no extra options in which case old files are silently unlinked and writing into links isn't possible, or 3. run with --overwrite which will keep files but write into them, including writing into links, including writing into links placed in the target dir ad-hoc which could be considered a feature.

Assuming I understand the options correctly, perhaps less confusing set of options would be something like:

- An option -k/--dont-replace (which would be the current -k option)

- And an option --replace (which would be what seems to be the current default behavior and which would be an option set by default)

- And an option --overwrite-in-place (which would be the current --overwrite that also writes into links).

It seems to me like the current --overwrite should almost never be used, since unlinking files is the default anyway. But the help page suggests for any replacing, it would need to be used since it literally says "replace existing files".

In any case, I might be understanding the code wrong entirely.

Regards,

Ellie

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to