]> git.ipfire.org Git - thirdparty/tar.git/log
thirdparty/tar.git
4 days agotar: reuse FD when extracting hard links master
Paul Eggert [Thu, 30 Jul 2026 06:10:27 +0000 (23:10 -0700)] 
tar: reuse FD when extracting hard links

* src/extract.c (rename_directory): Redo to accommodate
new semantics of fdbase1, and to use fds more intelligently.
* src/misc.c (fdbase_opendir): If ALTERNATE, it is now OK to use,
though not update, the main cache.  This makes it possible for the
caller to do linkat (N, "A", N, "B") instead of the
linkat (N, "A", N + 1, "B") it previously did, and this
saves some open and close calls on directories.

4 days agotar: open directories more efficiently
Paul Eggert [Tue, 28 Jul 2026 22:34:09 +0000 (15:34 -0700)] 
tar: open directories more efficiently

Without this patch, tar would open the parent of a directory
for search, then open the directory itself for search.
It's more efficient to just open the directory for search.
* src/create.c (create_archive, restore_parent_fd, chdir_do):
Use open_searchdir instead of opening by hand.
* src/misc.c (chdir_do): Use fdbase_opendir and fdbase_close
instead of openat and close, so that the fd is cached properly.
(chdirable): New function.
(fdbase_clear): Use it to avoid closing chdirable FDs.
(fdbase_close): New function.
(open_subdir): New arg OFLAGS.  All callers changed.
(fdbase_opendir): New arg CHILD_OFLAGS.  All callers changed.
Prefer AT_FDCWD for absolute file names, so that we need not
worry about chdir_fd == BADFD in that case.
Do not allow empty file names.
When replacing an old directory, do not close its fd if it
is chdirable.
(open_searchdir): New function.
* src/tar.c (decode_options): Do not worry about one_top_level_dir
and IS_ABSOLUTE_FILE_NAME (one_top_level_dir), as fdbase_opendir
now prefers AT_FDCWD for absolute file names.
(tar_stat_close): Use fdbase_close instead of close,
so that the fd is cached properly.

4 days ago--one-top-level clarifications
Paul Eggert [Wed, 22 Jul 2026 23:48:45 +0000 (16:48 -0700)] 
--one-top-level clarifications

Bring back documentation for --one-top-level absolute file names,
and clarify its behavior.  Allow --one-top-level only with
-x, -d, -t.
* src/misc.c (chdir_do): Do not pass -1 to openat.  Simplify now
that open_searchdir_how no longer has RESOLVE_BENEATH when
one_top_level_dir is absolute.  Fix errno confusion in messages.
* src/tar.c (decode_options): Allow --one-top-level only with -x,
-d, and -t.  Do not use RESOLVE_BENEATH if --one-top-level=/foo is
used; this simplifies chdir_do.

4 days agoSave work if one_top_level_dir is absolute
Paul Eggert [Wed, 22 Jul 2026 23:39:30 +0000 (16:39 -0700)] 
Save work if one_top_level_dir is absolute

* src/misc.c (chdir_arg): Optimize --one-top-level=X where X is an
absolute file name.

4 days agoSave a syscall in trivial extract_dir
Paul Eggert [Wed, 22 Jul 2026 23:37:35 +0000 (16:37 -0700)] 
Save a syscall in trivial extract_dir

* src/extract.c (trivial_base_name): New function.
(extract_dir): Use it.

4 days agoRemove struct wd.one_top_level
Paul Eggert [Sun, 19 Jul 2026 15:45:03 +0000 (08:45 -0700)] 
Remove struct wd.one_top_level

This merely refactors.
* src/misc.c: Don’t include assert.h.
(struct wd.one_top_level): Remove.  All uses changed to say that
it’s a one_top_level directory iff its index is odd and
one_top_level_dir is nonnull.  This simplifies the code and
removes the need for a couple of ‘assert’s.  This code
uses ~+X instead of ~X to pacify gcc -Wbool-operation.

4 days agoImprove dir checking in make_directories
Paul Eggert [Sun, 19 Jul 2026 04:29:53 +0000 (21:29 -0700)] 
Improve dir checking in make_directories

Prefer faccessat to fstatat for dir checking.
Also, don’t bother doing either check if caller
is about to check the rough equivalent anyway.
* src/extract.c (make_directories): Now static.
2nd arg is now a three-way flag.  All uses changed.
Use faccessat instead of fstatat, to avoid EOVERFLOW issues.
(create_dir): New function, for use outside this module.
External caller changed.
(maybe_recoverable): Set *INTERDIR_MADE if make_directories
said we made the parent.

4 days agoAvoid need to append "/." for make_directories
Paul Eggert [Sat, 18 Jul 2026 20:24:40 +0000 (13:24 -0700)] 
Avoid need to append "/." for make_directories

* src/extract.c (make_directories): New arg JUST_PARENT.
All callers changed.
* src/misc.c (struct wd.name, add_wd, chdir_arg):
Use char *, not char const *, to let make_directories
temporarily alter slashes.  All uses changed.
(chdir_do): Do not create a new name with trailing "/."
because make_directories no longer needs this.

4 days agoSimplify make_directories API
Paul Eggert [Sat, 18 Jul 2026 19:49:40 +0000 (12:49 -0700)] 
Simplify make_directories API

* src/extract.c (make_directories): Return a 3-way int rather than
an int (actually a bool) and another optional bool via a pointer.
All callers changed.  In comment, make it clearer what the
return value means.  Also, improve behavior in a small way: when
issuing a diagnostic on MS-Windows-like systems, use the original
directory name rather than translating '\\' to '/'.

4 days agoImprove --keep-directory-symlink performance
Paul Eggert [Wed, 13 May 2026 03:31:59 +0000 (20:31 -0700)] 
Improve --keep-directory-symlink performance

* src/extract.c (is_directory_link): Remove; no longer needed.
(extract_dir): If --keep-directory-symlink, avoid the need
to call issymlinkat if either --dereference is not specified,
or if the plain stat fails.  This saves a syscall, simplifies
the code a bit, and should simplify future changes.

4 days agoGo back to simpler chdir_arg API
Paul Eggert [Sat, 18 Jul 2026 18:13:38 +0000 (11:13 -0700)] 
Go back to simpler chdir_arg API

* src/misc.c (add_wd, ensure_wd): New functions, replacing ...
(grow_wd): .. this function, for clarity.  All uses changed.
(chdir_arg): Omit 2nd arg, to keep callers simpler.
All uses changed.  Instead of being recursive, be iterative;
this is part of the simplification.

4 days agoAdd comment about deducing --one-top-level name
Paul Eggert [Thu, 4 Jun 2026 16:32:11 +0000 (09:32 -0700)] 
Add comment about deducing --one-top-level name

4 days agoGet rid of create_dir
Pavel Cahyna [Mon, 22 Jun 2026 15:18:02 +0000 (17:18 +0200)] 
Get rid of create_dir

It turns out that make_directories can do what we need (create all
directories in a path) if we append a dummy "." component, as it creates
directories up to and excluding the last component of the path.

Also, do not avoid using delay_set_stat on the newly created
directories. This matches the rest of the code and avoids potentially
leaving the newly-created directories with too open permissions.
This requires some workarounds to cope with
apply_nonancestor_delayed_set_stat and mark_metadata_set problems: do it
as in the rest of the code - apply the stats before proceeding with
extraction of anything else.

4 days agoEliminate redundant chdir_do
Pavel Cahyna [Mon, 22 Jun 2026 13:17:07 +0000 (15:17 +0200)] 
Eliminate redundant chdir_do

If one-top-level is not provided, chdir_do is a no-op.

4 days agoAdd tests for cyclic renames
Pavel Cahyna [Mon, 25 May 2026 17:42:59 +0000 (19:42 +0200)] 
Add tests for cyclic renames

Using options to extract to a subdirectory: one test with -C,
another with --one-top-level.

4 days agoRevert "tar: incremental 'X' follows --one-top-level"
Pavel Cahyna [Thu, 21 May 2026 21:23:03 +0000 (23:23 +0200)] 
Revert "tar: incremental 'X' follows --one-top-level"

This reverts commit 79d61af0e118a9368425729f624a66e1065be61e.

4 days agoDraft patch for openat2 changes vs --one-top-level
Pavel Cahyna [Tue, 12 May 2026 15:56:44 +0000 (08:56 -0700)] 
Draft patch for openat2 changes vs --one-top-level

The patch leverages the existing -C code. In order to do that, every
entry in the wd[] table gets another companion entry in the table that
represents the --one-top-level directory. There is one additional field
in each entry that allows skipping the companion entries if they are not
desired.

The actual directory is created lazily by chdir_do() if needed, as you
requested, to avoid empty "a/foo" after --one-top-level=foo -C a -C b.

The patch "by the way" fixes also extraction of hardlinks with
--one-top-level which currently is broken in the typical case (the
transform is not applied to the target, so the hardlink is wrong).

The patch does not yet handle the --show-transformed case with
--one-top-level that you discussed in another subthread. As a result, two
tests now fail (onetop02.at and onetop04.at). I suppose that this would
be quite easy to fix.

Another issue that I am aware of is that I am not sure whether to call
repair_delayed_set_stat and/or delay_set_stat on the newly created
directories like extract_dir() does (the whole delay_set code is abit
mysterious to me).

Use of --create together with --one-top-level should probably be
forbidden, as unlink.c uses wd[] in a way that will likely break in the
presence of companion entries (the chdir_do call in
flush_deferred_unlinks).

Show the one-top-level arg as a transformation

9 days agoFix --set-mtime-command.
Sergey Poznyakoff [Sat, 25 Jul 2026 14:10:11 +0000 (17:10 +0300)] 
Fix --set-mtime-command.

This fixes a bug introduced by 281e03ec6.

* src/system.c (sys_exec_setmtime_script): Increase buflen by
value of nread.

11 days agoAssume directory members have size=0.
Sergey Poznyakoff [Thu, 23 Jul 2026 07:42:56 +0000 (10:42 +0300)] 
Assume directory members have size=0.

Since commit b8d8a61b, tar started honoring size field in headers
of the directory archive members when listing and extracting. That
doesn't seem right: although GNU tar always stores 0 for such members,
there are other tar implementation that don't. As a result, GNU tar
skips the actual directory contents when listing or extracting archives
created by such implementations.

This commit fixes that by assuming that size is 0 for directory archive
members.

* src/list.c (member_is_dir): Restore function.
(skim_member): Don't apply skim_file to directory members.
* tests/skipdir.at: Fix expectations.

11 days agoUpdate paxutils
Sergey Poznyakoff [Thu, 23 Jul 2026 06:00:22 +0000 (09:00 +0300)] 
Update paxutils

12 days agoCheck if the dumpdir read from the archive is well-formed before using it.
Sergey Poznyakoff [Tue, 21 Jul 2026 19:49:04 +0000 (22:49 +0300)] 
Check if the dumpdir read from the archive is well-formed before using it.

* src/common.h (dumpdir_ok): New proto.
* src/incremen.c (dumpdir_ok): Take size as the second argument.
Verify if the last byte is 0 and the dumpdir contains 0 or more
nul-terminated strings.
(get_gnu_dumpdir): Check if the obtained dumpdir is ok. Clear the
is_dumpdir flag if it is not.
* src/xheader.c (dumpdir_decoder) Verify if the obtained dumpdir is
ok.

4 weeks agoAvoid acl_ prefix for functions
Pavel Cahyna [Wed, 24 Jun 2026 16:45:30 +0000 (18:45 +0200)] 
Avoid acl_ prefix for functions

The acl.h header from libacl uses acl_ prefix for its functions. Avoid
defining functions with the same name in order to protect its namespace.

6 weeks ago* list.c: Correct some historical commentary.
Paul Eggert [Sat, 20 Jun 2026 07:54:28 +0000 (00:54 -0700)] 
* list.c: Correct some historical commentary.

6 weeks agotar: ignore nonzero sizes in hard links etc
Paul Eggert [Sat, 20 Jun 2026 07:28:17 +0000 (00:28 -0700)] 
tar: ignore nonzero sizes in hard links etc

Problem reported by Antonio Teixeira.
* src/list.c (read_header): When POSIX says a size field must
be zero or does not represent a data count, treat it as zero.
* tests/extrac32.at: Update to match new behavior.
We now treat hard link sizes as zero even when the size fields are
nonzero, and this means the “injected” file is treated as valid
regardless of whether we list or extract.
* tests/extrac34.at: New test.
* tests/Makefile.am (TESTSUITE_AT), tests/testsuite.at: Add it.

7 weeks agoFix extracting over symlinks with --dereference
Sergey Poznyakoff [Thu, 11 Jun 2026 13:33:15 +0000 (16:33 +0300)] 
Fix extracting over symlinks with --dereference

Extraction over symlink to a directory was broken in 75b03fdff4.
See https://savannah.gnu.org/bugs/index.php?68368

* src/tar.c (decode_options): Don't enable RESOLVE_BENEATH mode
if --dereference is given.
* tests/extrac33.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
* tests/extrac13.at: Add a keyword.
* tests/extrac31.at: Remove --absolute-names keyword: that option
is never used in the testcase. Add CVE-2025-45582 keyword instead.

7 weeks agoMinor fix in the testsuite
Sergey Poznyakoff [Thu, 11 Jun 2026 13:32:17 +0000 (16:32 +0300)] 
Minor fix in the testsuite

* tests/extrac32.at: Remove debugging code.

7 weeks agoFix doc generation
Sergey Poznyakoff [Thu, 11 Jun 2026 11:40:02 +0000 (14:40 +0300)] 
Fix doc generation

* doc/Makefile.am: Use tidy mode for texi2dvi; don't use
the deprecated texi2html.
* doc/tar.texi: Fix rendering of o-umlaut.
* doc/texify.sed: Likewise.

7 weeks agoFix descriptions of -C and -T options.
Sergey Poznyakoff [Thu, 11 Jun 2026 10:56:02 +0000 (13:56 +0300)] 
Fix descriptions of -C and -T options.

This fixes discrepancies reported in https://savannah.gnu.org/bugs/?68253
and https://savannah.gnu.org/bugs/?68408.

* doc/tar.texi: Emphasize that the -C option does not affect filename
arguments to another options, such as -f, -T or the like.  Improve
the description of -T.
* doc/tar.1: Fix descriptions of -C and -T.

2 months agoPacify GCC 16.1 -Wanalyzer-use-of-uninitialized-value
Paul Eggert [Mon, 11 May 2026 22:37:37 +0000 (15:37 -0700)] 
Pacify GCC 16.1 -Wanalyzer-use-of-uninitialized-value

This fixes a false positive with gcc 16.1.1 20260501 (Red Hat
16.1.1-1) on x86-64.
* src/extract.c (set_stat): Use differently-worded but equivalent test
to help the compiler see that ts[0].tv_sec is used only if sedt.

2 months agobuild: update gnulib submodule to latest
Paul Eggert [Mon, 11 May 2026 22:24:56 +0000 (15:24 -0700)] 
build: update gnulib submodule to latest

2 months agotar: remove no-longer-accurate comment
Paul Eggert [Mon, 11 May 2026 21:16:28 +0000 (14:16 -0700)] 
tar: remove no-longer-accurate comment

2 months agoQuote --set-mtime-command file names
Paul Eggert [Mon, 11 May 2026 21:12:03 +0000 (14:12 -0700)] 
Quote --set-mtime-command file names

Problem reported by Raphael Karger.
* src/system.c: Include quotearg.h.
(sys_exec_setmtime_script): Quote the file name for the shell.

3 months agoUse mkdtempat instead of mkdtemp
Paul Eggert [Mon, 13 Apr 2026 06:58:22 +0000 (23:58 -0700)] 
Use mkdtempat instead of mkdtemp

This fixes an interaction of -C with incremental 'X'.
Problem reported by Pavel Cahyna.
* gnulib.modules: Remove mkdtemp.
Add tempname, since our mkdtempat uses it.
* lib/mkdtempat.c, lib/mkdtempat.h: New files.
* lib/Makefile.am (noinst_HEADERS): Add mkdtempat.h.
(libtar_a_SOURCES): Add mkdtempat.c.
* src/incremen.c: Include mkdtempat.h.
(purge_directory): Use mkdtempat, not mkdtemp.

3 months agotar: comment struct fdbase
Paul Eggert [Sun, 12 Apr 2026 15:58:01 +0000 (08:58 -0700)] 
tar: comment struct fdbase

* src/common.h (struct fdbase): Add comment.

3 months agotar: ENFILE is like EMFILE
Paul Eggert [Thu, 9 Apr 2026 16:19:25 +0000 (09:19 -0700)] 
tar: ENFILE is like EMFILE

* src/create.c (open_failure_recover):
* src/misc.c (fdbase_opendir):
Treat ENFILE like EMFILE.

3 months agotar: incremental 'X' follows --one-top-level
Paul Eggert [Wed, 8 Apr 2026 16:03:14 +0000 (09:03 -0700)] 
tar: incremental 'X' follows --one-top-level

* src/incremen.c (purge_directory):
Also respect --one-top-level when handling 'X'.

3 months agoSimplify one_top_level_dir logic
Paul Eggert [Tue, 7 Apr 2026 18:47:13 +0000 (11:47 -0700)] 
Simplify one_top_level_dir logic

* src/tar.c (one_top_level_option): Remove.  All uses removed.
All external uses changed to equivalent of !!one_top_level_dir.
(decode_options): Set one_top_level_dir to be consistent with
the old one_top_level_option.

3 months ago--one-top-level now keeps "../" and ".../"
Paul Eggert [Tue, 7 Apr 2026 18:11:21 +0000 (11:11 -0700)] 
--one-top-level now keeps "../" and ".../"

* src/list.c (enforce_one_top_level): Do not strip prefixes like
"../" (which should not be allowed unless -P) and ".../" (which
are ordinary file names).  The "../" not being allowed should be
addressed in a different way.

3 months agoDisallow --one-top-level=''.
Paul Eggert [Tue, 7 Apr 2026 18:05:23 +0000 (11:05 -0700)] 
Disallow --one-top-level=''.

* src/tar.c (decode_options): Do not accept an empty string
as a relative file name.

3 months agoPrefer signed int in sparse.c
Paul Eggert [Sat, 4 Apr 2026 21:53:31 +0000 (14:53 -0700)] 
Prefer signed int in sparse.c

* src/sparse.c (pax_dump_header_0, floorlog10)
(pax_dump_header_1, struct ok_n_block_ptr, decode_num)
(pax_decode_header): Prefer signed to unsigned integers
where either will do, as this allows for better runtime
checking for overflow.  The integers in question cannot
be negative or greater than INTMAX_MAX anyway.

3 months agotar: strip '/' from incremental 'X' entries
Paul Eggert [Sat, 4 Apr 2026 17:50:08 +0000 (10:50 -0700)] 
tar: strip '/' from incremental 'X' entries

Problem identified by Michał Majchrowicz and Marcin Wyczechowski,
members of the AFINE Team.
* gnulib.modules: Add mempcpy, which we were already using anyway.
* src/incremen.c (purge_directory):
Use a safer suffix for 'X' entries, too.
Also, do not turn "/" to "//" or "//" to "///" (possible only if -P).

4 months agoPrefer UNNAMED to MAYBE_UNUSED
Paul Eggert [Sun, 22 Mar 2026 19:19:40 +0000 (12:19 -0700)] 
Prefer UNNAMED to MAYBE_UNUSED

* src/buffer.c, src/compare.c, src/exclist.c, src/extract.c:
* src/sparse.c, src/tar.c, src/xheader.c:
UNNAMED is for when an identifier is never used and so does not
need a name.  Prefer it to MAYBE_UNUSED when that is the case.
Also, drop MAYBE_UNUSED in some places where the identifier
is always used.

4 months agoUpdate tar.h comments
Paul Eggert [Sun, 22 Mar 2026 19:19:40 +0000 (12:19 -0700)] 
Update tar.h comments

* src/tar.h: Update comments.

4 months agoFix more -t/-x discrepancies
Paul Eggert [Sun, 22 Mar 2026 19:19:40 +0000 (12:19 -0700)] 
Fix more -t/-x discrepancies

Problem reported by Guillermo de Angel in:
https://lists.gnu.org/r/bug-tar/2026-03/msg00007.html
* THANKS: Add him, and sort.
* src/extract.c (extract_dir, extract_file):
* src/incremen.c (purge_directory):
Do not call skip_member, as the caller now does that, and does it
more reliably.
* src/extract.c (extract_file):
Mark file as skipped when we’ve read it.
(extract_archive): Always call skip_member after extracting,
as it suppresses the skip as needed.
* src/incremen.c (try_purge_directory): Remove; no longer
needed.  Move internals to purge_directory.
* src/list.c (read_header): Do not treat LNKTYPE header as having
size zero, as it can be nonzero (e.g., ‘pax -o linkdata’).
Set info->skipped field according to how the header was read.
(member_is_dir): Remove; no longer needed.
(skim_member): Skip directory data too, unless it’s already been
skipped (i.e., read).
* tests/extrac32.at: New file.
* tests/Makefile.am (TESTSUITE_AT):
* tests/testsuite.at:
Add it.
* tests/skipdir.at (skip directory members):
Fix test to match the correct behavior.
This fixes a bug introduced in commit
b009124ffde415515081db844d7a104e1d1c6c58
dated 2025-05-12 17:17:21 +0300.

4 months agobuild: update gnulib submodule to latest
Paul Eggert [Sun, 22 Mar 2026 19:19:06 +0000 (12:19 -0700)] 
build: update gnulib submodule to latest

4 months agoUpdate NEWS for previous patch
Paul Eggert [Thu, 12 Mar 2026 19:31:18 +0000 (12:31 -0700)] 
Update NEWS for previous patch

4 months agoRespect --ignore-failed-read in file_removed_diag (bug#68075)
Marco Nenciarini [Wed, 11 Mar 2026 18:18:26 +0000 (19:18 +0100)] 
Respect --ignore-failed-read in file_removed_diag (bug#68075)

* src/misc.c (file_removed_diag): Guard set_exit_status call
with !ignore_failed_read_option, consistent with stat_diag and
other diagnostic functions.
* tests/filerem03.at: New test.
* tests/testsuite.at: Include it.
* tests/Makefile.am: Add it.
Copyright-paperwork-exempt: yes

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
4 months agoUpdate NEWS for previous patch
Paul Eggert [Tue, 10 Mar 2026 16:46:22 +0000 (09:46 -0700)] 
Update NEWS for previous patch

4 months agoFix wrong fd in restore_parent_fd fallback path
Weixie Cui [Mon, 9 Mar 2026 11:37:59 +0000 (19:37 +0800)] 
Fix wrong fd in restore_parent_fd fallback path

Use fstat(origfd) instead of fstat(parentfd) when verifying the
alternatively-opened directory; parentfd is invalid in this branch.

Copyright-paperwork-exempt: yes

5 months agoDocument timestamp resolution more accurately
Paul Eggert [Wed, 18 Feb 2026 20:41:19 +0000 (12:41 -0800)] 
Document timestamp resolution more accurately

6 months agotar: --one-top-level=DIR must be relative
Paul Eggert [Fri, 30 Jan 2026 20:48:48 +0000 (12:48 -0800)] 
tar: --one-top-level=DIR must be relative

* src/tar.c (decode_options): Require --one-top-level operand
to be relative.

6 months agomaint: pacify -Wzero-as-null-pointer-constant
Paul Eggert [Sat, 24 Jan 2026 01:25:45 +0000 (17:25 -0800)] 
maint: pacify -Wzero-as-null-pointer-constant

Recent Gnulib enables this warning, and it did find a bug
in GNU Tar, so pacify GCC everywhere else by preferring
NULL to 0 for pointers.

6 months agoFix EOF return from wordsplit_finish
Paul Eggert [Sat, 24 Jan 2026 01:04:58 +0000 (17:04 -0800)] 
Fix EOF return from wordsplit_finish

* lib/wordsplit.c (wordsplit_finish):
Fix typo caught by -Wzero-as-null-pointer-constant

6 months agoSync bootstrap from gnulib
Paul Eggert [Sat, 24 Jan 2026 00:00:09 +0000 (16:00 -0800)] 
Sync bootstrap from gnulib

6 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Fri, 23 Jan 2026 23:59:06 +0000 (15:59 -0800)] 
build: update gnulib and paxutils submodules to latest

* src/extract.c: Include issymlinkat.h, not issymlink.h.

6 months agoUpdate copyright years
Paul Eggert [Fri, 23 Jan 2026 23:41:58 +0000 (15:41 -0800)] 
Update copyright years

UPDATE_COPYRIGHT_USE_INTERVALS=1 \
$HOME/src/gnu/gnulib/build-aux/update-copyright \
  $(git ls-files | sed -e '/^gnulib$/d
   /^paxutils$/d
   /^COPYING$/d
   /\/fdl.texi$/d')
sed -i '2000,${
    /^Copyright @copyright/d
    s/^[0-9]*--\(2026 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi

8 months agoFix commit typo when bringing back placeholders
Paul Eggert [Thu, 27 Nov 2025 19:11:25 +0000 (11:11 -0800)] 
Fix commit typo when bringing back placeholders

Problem reported by Pavel Raiskup in:
https://lists.gnu.org/r/bug-tar/2025-11/msg00028.html
* src/extract.c (contains_dot_dot): Bring back this function here,
from its former location in src/names.c.  Make it static since
it is used only in this compilation unit.

8 months agoBring back placeholders
Paul Eggert [Thu, 27 Nov 2025 04:14:08 +0000 (20:14 -0800)] 
Bring back placeholders

They can still be useful if -h is used.  See Pavel Cahyna in:
https://lists.gnu.org/r/bug-tar/2025-11/msg00026.html
while we’re at it bring them back if -P is used,
as they can still be useful there too.
* src/extract.c (HAVE_BIRTHTIME, BIRTHTIME_EQ):
Bring back these macros.
(struct delayed_link, struct string_list):
Bring back these structs.
(delayed_link_table, delayed_link_head, delayed_link_tail):
Bring back these static vars.
(dl_hash, dl_compare, find_direct_ancestor)
(find_delayed_link_source, create_placeholder_file)
(apply_delayed_link, apply_delayed_links):
Bring back these static functions.
(mark_metadata_set): Rename from mark_after_links.  All uses changed.
(extract_link, extract_symlink):
Create placeholders as before, except only if -P or -h are used.
(extract_finish): Deal with delayed links, as before.

8 months agoSupport gnulib-style timestamps in checkpoint logs
Paul Eggert [Sun, 23 Nov 2025 17:44:03 +0000 (09:44 -0800)] 
Support gnulib-style timestamps in checkpoint logs

* gnulib.modules: Add nstrftime-limited, time_rz.  Sort.
* src/checkpoint.c: Include <strftime.h>.
(format_checkpoint_string): Use nstrftime instead of strftime.
Also fix an obscure bug on platforms that lack tm_gmtoff+tm_zone by
calling tzalloc on those platforms; if it fails, fall back on gmtime.
Also, use fwrite instead of fprintf, since we typically know the
length already and this gives us a more-accurate byte count
in case there are partial writes.

8 months agobuild: update gnulib submodule to latest
Paul Eggert [Fri, 21 Nov 2025 01:26:34 +0000 (17:26 -0800)] 
build: update gnulib submodule to latest

8 months agoPort to C23 qualifier-generic fns like strchr
Paul Eggert [Sun, 23 Nov 2025 17:50:37 +0000 (09:50 -0800)] 
Port to C23 qualifier-generic fns like strchr

* src/checkpoint.c (getarg):
* src/tar.c (expand_pax_option):
Const-qualify results of strchr etc. if args are const-qualified.

8 months agobuild: update gnulib submodule to latest
Paul Eggert [Tue, 18 Nov 2025 00:35:54 +0000 (16:35 -0800)] 
build: update gnulib submodule to latest

8 months agoPrefer countof to sizeof / sizeof
Paul Eggert [Sat, 15 Nov 2025 23:49:23 +0000 (15:49 -0800)] 
Prefer countof to sizeof / sizeof

C2y plans to introduce a new countof operator that will be
convenient for GNU tar, so start using it now via Gnulib.
* gnulib.modules: Add stdcountof-h.
* lib/wordsplit.c, src/buffer.c, src/suffix.c, src/tar.c:
Include stdcountof.h, and prefer countof (X) to sizeof X / sizeof *X.

8 months agoPort new extraction test to FreeBSD 15
Paul Eggert [Sat, 15 Nov 2025 21:56:56 +0000 (13:56 -0800)] 
Port new extraction test to FreeBSD 15

* tests/extrac31.at (extracting untrusted incremental):
Port to FreeBSD 15 wording.

8 months agoPort to compilers where COMMON_INLINE is static
Paul Eggert [Sat, 15 Nov 2025 21:38:44 +0000 (13:38 -0800)] 
Port to compilers where COMMON_INLINE is static

Problem found with clang 15.0 on CheriBSD.
* src/names.c (namelist_match, register_match):
Now plain static, not static COMMON_INLINE, since the later
could mean the declaration is ‘static static’ which is not allowed.

8 months agoPacify clang 14 -Wbitwise-conditional-parentheses
Paul Eggert [Sat, 15 Nov 2025 21:21:59 +0000 (13:21 -0800)] 
Pacify clang 14 -Wbitwise-conditional-parentheses

* src/common.h (add_printf):
* src/sparse.c (decode_num):
Parenthesize to pacify Apple clang version 14.0.0 (clang-1400.0.29.202).

8 months agoSkip sparse test on non-sparse file systems
Paul Eggert [Sat, 15 Nov 2025 20:55:06 +0000 (12:55 -0800)] 
Skip sparse test on non-sparse file systems

* tests/sparse05.at (listing sparse files bigger than 2^33 B):
If there were problems generating BIGFILE remove it,
as it has likely exhausted the file system.
Problem found on Darwin 21.6 APFS.

8 months agoAdjust to Gnulib strftime changes for macOS
Paul Eggert [Sat, 15 Nov 2025 09:05:05 +0000 (01:05 -0800)] 
Adjust to Gnulib strftime changes for macOS

Stop using the fprintftime module, as as with recent Gnulib changes
it breaks the build on macOS, and fixing this would drag in threading
libraries and macOS-specific libraries that are overkill for tar.
Instead, just use strftime; that’s good enough here and arguably
better in case someone attacks tar with a huge time format string.
* gnulib.modules: Remove fprintftime.
* src/checkpoint.c: Do not include fprintftime.
(format_checkpoint_string): Always output some useful info (a decimal
seconds count), even if localtime fails. Do not output more than
256 bytes of time info, as that’s likely a DoS attack.  Stick with
plain strftime, as fprintftime’s extra features are overkill here.

8 months agoPort intmax macro to strict C11
Paul Eggert [Sat, 15 Nov 2025 08:55:47 +0000 (00:55 -0800)] 
Port intmax macro to strict C11

Needed for Apple clang version 14.0.0 (clang-1400.0.29.202).
* src/common.h (intmax): Define macro only if _Generic works, and
use _Generic in it rather that using EXPR_SIGNED.  This is needed
to make the first argument of verify_expr an integer constant
expression, which is required for strict C11.  Although GCC is
smart enough to treat (1 ? 0 : V) as an integer constant
expression even if V is an integer variable, C11 does not require
support for this sort of thing.

8 months agoPort new tests to Solaris 10 strerror
Paul Eggert [Sat, 15 Nov 2025 07:55:24 +0000 (23:55 -0800)] 
Port new tests to Solaris 10 strerror

* tests/extrac31.at: Adjust to Solaris 10 diagnostics.

8 months agoDo not create empty placeholder files
Paul Eggert [Fri, 14 Nov 2025 06:59:24 +0000 (22:59 -0800)] 
Do not create empty placeholder files

* src/extract.c (HAVE_BIRTHTIME, BIRTHTIME_EQ, struct delayed_link)
(delayed_link_table, delayed_link_head delayed_link_tail)
(struct string_list, dl_hash, dl_compare, find_direct_ancestor)
(find_delayed_link_source, create_placeholder_file, apply_delayed_link)
(apply_delayed_links): Remove.  All uses removed.
(struct delayed_set_stat): New member metadata_set,
replacing after_links.  All uses changed.
(apply_nonancestor_delayed_set_stat): Arg METADATA_SET replaces
the old AFTER_LINKS.  All callers changed.
(extract_archive): Do not worry about "..", since openat2
now does that for us.
* src/names.c (first_dot_dot): Remove.  All uses removed.

8 months agoUse openat2 to jailify the extraction directory
Paul Eggert [Thu, 13 Nov 2025 21:44:10 +0000 (13:44 -0800)] 
Use openat2 to jailify the extraction directory

This addresses CVE-2025-45582.
* gnulib.modules: Add openat2.
* src/misc.c (open_subdir): New static function.
(fdbase_opendir): Use it.
* src/tar.c (open_searchdir_how): New var, replacing and
augmenting open_searchdir_flags.  All uses changed.
* tests/extrac31.at: New file.
* tests/Makefile (TESTSUITE_AT), tests/testuite.at: Add it.

8 months agoOmit trailing white space and empty lines
Paul Eggert [Fri, 14 Nov 2025 01:13:35 +0000 (17:13 -0800)] 
Omit trailing white space and empty lines

8 months agoStandardize on “working directory”
Paul Eggert [Fri, 14 Nov 2025 01:07:36 +0000 (17:07 -0800)] 
Standardize on “working directory”

8 months agoUse fewer flags when opening directories
Paul Eggert [Thu, 13 Nov 2025 21:18:27 +0000 (13:18 -0800)] 
Use fewer flags when opening directories

This doesn’t change behavior; it is a refactoring for
compatibility with a future patch that will use Linux’s
openat2 syscall, which is pickier about flags.
* src/tar.c (decode_options): When searching directories,
do not use O_NOCTTY, O_NONBLOCK, and O_NOATIME.
openat2 rejects all three flags if O_PATH is used.
The first two flags are definitely irrelevant for directories,
and O_NOATIME probably doesn’t matter either.

8 months agoImprove performance of relative opendir
Paul Eggert [Thu, 13 Nov 2025 16:15:26 +0000 (08:15 -0800)] 
Improve performance of relative opendir

* src/misc.c (fdbase_opendir): When the new directory is a
subdirectory of the old one, open relative to the old one rather
than relative all the way back to chdir_fd, and if that open fails
for a non-EMFILE reason, keep rather than discard the old directory.

8 months agoWork around Oracle Developer Studio compiler bug
Paul Eggert [Fri, 14 Nov 2025 20:19:30 +0000 (12:19 -0800)] 
Work around Oracle Developer Studio compiler bug

* src/create.c (dump_file0): Reword.

8 months agoCache parent directories
Paul Eggert [Thu, 13 Nov 2025 01:33:11 +0000 (17:33 -0800)] 
Cache parent directories

Although this might help (or hurt) performance, the main
motivation is to make it easier in future commits
to prevent tarballs from escaping the extraction directory.
* src/common.h: (BADFD): New constant.
(struct fdbase): New type.
* src/create.c (dump_file0): Use parent->fd instead of caching
it into a local, as the latter approach is now awkward.
* src/extract.c (extract_link): Don’t save errno unless needed.
* src/misc.c (safer_rmdir): New arg F.  All callers changed.
(maybe_backup_file): Construct full after_backup_name, now
that find_backup_file_name no longer does that for us.
(chdir_fd): Now static not extern, as other modules now use fdbase.
(fdbase_cache): New static var.
(fdbase_clear): New function.  Call it whenever removing
or renaming directories or symlinks to directories.
(fdbase_opendir): New static function.
(fdbase, fdbase1): New functions.  Call them whenever the
code formerly passed chdir_fd to a syscall.

8 months agoPrefer issymlinkat
Paul Eggert [Tue, 11 Nov 2025 16:08:58 +0000 (08:08 -0800)] 
Prefer issymlinkat

* gnulib.modules: Add issymlinkat, already an indirect dependency.
* src/extract.c: Include issymlink.h.
(is_directory_link, open_output_file):
Prefer issymlinkat to doing it by hand.

8 months agoMake xclose static
Paul Eggert [Sun, 9 Nov 2025 21:29:03 +0000 (13:29 -0800)] 
Make xclose static

* src/buffer.c (xclose): Move from here ...
* src/system.c: ... to here, and make it static.

8 months agoPrefer O_PATH to O_SEARCH on Linux kernels
Paul Eggert [Sun, 9 Nov 2025 19:12:13 +0000 (11:12 -0800)] 
Prefer O_PATH to O_SEARCH on Linux kernels

* src/tar.c (decode_options): Prefer O_PATH to an O_SEARCH that is
actually O_RDONLY.

8 months agoPrefer streq/memeq when they will do
Paul Eggert [Sun, 9 Nov 2025 00:01:14 +0000 (16:01 -0800)] 
Prefer streq/memeq when they will do

Gnulib’s new streq and memeq functions make code a bit more
readable and, we hope, a bit more reliable and easy to maintain.
* gnulib.modules: Add stringeq.
* lib/wordsplit.c (wordsplit_find_env):
* src/buffer.c (check_compressed_archive, check_tty)
(_open_archive, new_volume, try_new_volume)
(drop_volume_label_suffix):
* src/checkpoint.c (checkpoint_compile_action):
* src/compare.c (process_rawdata, diff_symlink):
* src/create.c (cachedir_file_p):
* src/delete.c (delete_archive_members):
* src/exclist.c (hg_addfn, get_vcs_ignore_file):
* src/extract.c (ds_compare, remove_delayed_set_stat)
(fixup_delayed_set_stat, apply_nonancestor_delayed_set_stat)
(extract_link):
* src/incremen.c (nfs_file_stat, compare_directory_canonical_names)
(procdir):
* src/list.c (read_header, decode_header):
* src/misc.c (replace_prefix):
* src/names.c (uname_to_uid, gname_to_gid, read_next_name)
(name_compare):
* src/sparse.c (check_data_region):
* src/suffix.c (find_compression_suffix):
* src/system.c (sys_detect_dev_null_output)
(sys_child_open_for_compress, sys_child_open_for_uncompress):
* src/tar.c (set_archive_format, tar_set_quoting_style)
(optloc_eq, set_use_compress_program_option, decode_signal)
(report_textual_dates, decode_options):
* src/update.c (update_archive):
* src/warning.c (set_warning_option):
* src/xattrs.c (xattrs_xattrs_set):
* src/xheader.c (xheader_keyword_override_p)
(xheader_set_keyword_equal, locate_handler)
(xheader_protected_keyword_p):
Prefer memeq/streq to memcmp/strcmp when either will do.

8 months agoRefactor to avoid duplication in "./" scanning
Paul Eggert [Sat, 8 Nov 2025 00:26:32 +0000 (16:26 -0800)] 
Refactor to avoid duplication in "./" scanning

* src/exclist.c (excluded_name):
* src/misc.c (normalize_filename_x, must_be_dot_or_slash)
(chdir_arg):
Use dotslash or dotslashlen instead of doing things by hand.
* src/misc.c (slashlen, dotslashlen): New functions.
(safer_rmdir): Do not worry about unlinkat with AT_REMOVEDIR
succeeding on ".", as POSIX prohibits it, and it does not succeed
on any known platform. This simplifies the file name test.
Continue to worry about "/" though, as POSIX does allow
it to be removed.

8 months agochdir_id refactoring
Paul Eggert [Tue, 28 Oct 2025 02:40:47 +0000 (19:40 -0700)] 
chdir_id refactoring

This prepares for future changes that need directory IDs.
* src/common.h (struct chdir_id): New struct.
* src/extract.c (extract_dir): Use chdir_id to avoid duplicate stats.
* src/misc.c (struct wd): New member ID.
(grow_wd): New function, extracted from chdir_arg and that
also initializes id.err.
(chdir_arg): Use it.  Initialize id.err.
(chdir_id): New function.

8 months agoRemove unreachable assignment to mtime.tv_nsec
Paul Eggert [Fri, 14 Nov 2025 08:07:26 +0000 (00:07 -0800)] 
Remove unreachable assignment to mtime.tv_nsec

Caught by Oracle Developer Studio 12.6
* src/incremen.c (read_incr_db_01): Remove unreachable code.

8 months agoOmit duplicate declaration of ‘usage’
Paul Eggert [Fri, 14 Nov 2025 07:02:33 +0000 (23:02 -0800)] 
Omit duplicate declaration of ‘usage’

8 months ago* README-hacking: Add testing note.
Paul Eggert [Sun, 9 Nov 2025 19:07:05 +0000 (11:07 -0800)] 
* README-hacking: Add testing note.

8 months agoFix test to match paxutils quoting change
Paul Eggert [Sat, 8 Nov 2025 23:43:17 +0000 (15:43 -0800)] 
Fix test to match paxutils quoting change

* tests/incr08.at (filename normalization):
Adjust test to match quoting change in paxutils.

8 months agoUse Gnulib gendocs instead of our own
Paul Eggert [Sat, 8 Nov 2025 22:14:27 +0000 (14:14 -0800)] 
Use Gnulib gendocs instead of our own

I ported our fix into Gnulib so there’s no longer a need
for a separate copy.
* doc/Makefile.am (GENDOCS): Now in ../build-aux, not here.
* doc/gendocs.sh, doc/gendocs_template: Remove.
* gnulib.modules: Add gendocs.

8 months agomaint: sync bootstrap, fdl.texi from Gnulib
Paul Eggert [Sat, 8 Nov 2025 21:42:55 +0000 (13:42 -0800)] 
maint: sync bootstrap, fdl.texi from Gnulib

8 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Sat, 8 Nov 2025 20:18:52 +0000 (12:18 -0800)] 
build: update gnulib and paxutils submodules to latest

8 months agofix build error when compiling with --without-xattrs
Matteo Croce [Thu, 13 Nov 2025 01:17:22 +0000 (17:17 -0800)] 
fix build error when compiling with --without-xattrs

* src/extract.c (set_xattr):
* src/xattrs.c (xattrs_xattrs_add, xattrs_xattrs_get, xattrs_xattrs_set):
Add MAYBE_UNUSED.
Copyright-paperwork-exempt: yes

8 months agoQuote arguments in diagnostic messages.
David Leadbeater [Wed, 12 Nov 2025 11:09:02 +0000 (13:09 +0200)] 
Quote arguments in diagnostic messages.

Copyright-paperwork-exempt: yes

9 months agoVersion 1.35.90
Sergey Poznyakoff [Sun, 19 Oct 2025 06:39:14 +0000 (09:39 +0300)] 
Version 1.35.90

11 months agomaint: Update library names used by Gnulib.
Collin Funk [Thu, 12 Sep 2024 01:52:47 +0000 (18:52 -0700)] 
maint: Update library names used by Gnulib.

* src/Makefile.am (tar_LDADD):
* tests/Makefile.am (LDADD): Update library names according to Gnulib.

Copyright-paperwork-exempt: yes

11 months agoAvoid overrun when converting ns-resolution timestamps to text
Paul Eggert [Tue, 19 Aug 2025 00:14:13 +0000 (17:14 -0700)] 
Avoid overrun when converting ns-resolution timestamps to text

Caught by gcc -fsanitize=address.
Inspired by Matthias Andree’s bug report in:
https://lists.gnu.org/r/bug-tar/2025-08/msg00019.html
though I found this bug via a simple "make check"
with sanitization enabled.
* src/common.h (TIMESPEC_STRSIZE_BOUND):
Make room for leading '-', needed in addition to the '-' room
supplied by SYSINT_BUFSIZE due to the way code_timespec works.

11 months agoAvoid hash_meta_directory int overflow
Paul Eggert [Sat, 9 Aug 2025 23:13:39 +0000 (16:13 -0700)] 
Avoid hash_meta_directory int overflow

* src/incremen.c (hash_directory_meta):
Avoid possibility of signed integer overflow.

11 months agoUse Gnulib’s same-inode module
Paul Eggert [Sat, 9 Aug 2025 23:10:49 +0000 (16:10 -0700)] 
Use Gnulib’s same-inode module

This is more portable to non-POSIX systems.
However, don’t bother trying to port to systems
where st_ino is not a scalar of type dev_t,
as these systems no longer seem to be active targets
and it’s not worth the maintenance hassle.
* gnulib.modules: Add same-inode, now that we use it
explicitly rather than indirectly.
* src/compare.c (diff_link):
* src/create.c (compare_links, restore_parent_fd):
* src/incremen.c (compare_directory_meta, procdir):
* src/extract.c (dl_compare, repair_delayed_set_stat)
(apply_nonancestor_delayed_set_stat, extract_link)
(apply_delayed_link):
* src/names.c (add_file_id):
* src/system.c (sys_file_is_archive, sys_detect_dev_null_output):
Include same-inode.h, and prefer its macros and functions
to doing things by hand.
* src/create.c (struct link):
* src/extract.c (struct delayed_set_stat, struct delayed_link):
* src/incremen.c (struct directory):
* src/names.c (struct file_id_list):
Rename members to st_dev and st_ino so that SAME_INODE and
PSAME_INODE can be used on the type.  All uses changed.
* src/system.c (sys_compare_links): Remove.
All uses replaced by psame_inode.

11 months agomanual: remove '.info' suffix in manual names passed to @xref
Collin Funk [Fri, 8 Aug 2025 03:42:14 +0000 (20:42 -0700)] 
manual: remove '.info' suffix in manual names passed to @xref

Texinfo 7.2 began warning about the '.info' suffix in the manual names
passed to @xref and similar commands.  They eventually plan to stop
stripping the '.info' suffix internally which will lead to broken links
in the manuals without this change.

* doc/tar.texi (files): Remove '.info' suffix from manual name.

12 months ago--no-overwrite-dir no overwrite even temporarily
Paul Eggert [Sun, 27 Jul 2025 04:41:23 +0000 (21:41 -0700)] 
--no-overwrite-dir no overwrite even temporarily

Problem and fix reported by Pavel Cahyna in
https://lists.gnu.org/r/bug-tar/2025-01/msg00000.html
* src/extract.c (extract_dir): With --no-overwrite-dir,
skip the chmod if the directory already exists.
* tests/extrac23.at (--no-overwrite-dir on empty directory):
Move the part of the test that looks at a nonempty directory ...
* tests/extrac30.at: ... to this new file, because the test now
must be run as non-root.  Adjust the test to match the new behavior.
* tests/Makefile.am (TESTSUITE_AT), tests/testsuite.at: Add it.