]> git.ipfire.org Git - thirdparty/tar.git/log
thirdparty/tar.git
42 hours agoSupport gnulib-style timestamps in checkpoint logs master
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.

42 hours 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

42 hours 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.

7 days 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

9 days 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.

9 days 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.

9 days 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.

9 days 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).

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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

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

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

9 days 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.

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

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

9 days 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.

9 days 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.

9 days 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

9 days 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

12 days 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

13 days 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

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

3 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

3 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.

3 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.

3 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.

3 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.

3 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.

4 months agoUse flexible array member in struct dumpdir
Paul Eggert [Sat, 26 Jul 2025 07:47:48 +0000 (00:47 -0700)] 
Use flexible array member in struct dumpdir

* src/incremen.c: Include flexmember.h.
(struct dumpdir): contents is now a flexible member, not a pointer.
This is more idiomatic and slightly more efficient.
(dumpdir_create0): Adjust to the new struct dumpdir layout.

4 months agoAvoid undefined behavior in magic checking
Paul Eggert [Sat, 26 Jul 2025 07:27:01 +0000 (00:27 -0700)] 
Avoid undefined behavior in magic checking

* src/buffer.c (check_compressed_archive):
* src/list.c (read_header, decode_header):
Use memcmp, not strcmp, when looking for magic strings in
headers, since input headers are not guaranteed to be
strings and strcmp has undefined behavior otherwise.

4 months agoPort more code to UBSan, and fix alignment bug
Paul Eggert [Sat, 26 Jul 2025 03:39:32 +0000 (20:39 -0700)] 
Port more code to UBSan, and fix alignment bug

Problem with extract_file reported by Kirill Furman in:
https://lists.gnu.org/r/bug-tar/2025-07/msg00003.html
Since the UBSan thing seems to be a recurring issue,
I fixed other instances of the problem that I found.
Also, I noticed that the same line of code had another failure to
conform to C23’s rules for pointers (an alignment issue not caught
by UBSan), so I fixed that too.  None of these issues matter on
practical production hosts.
* src/common.h (charptr): New function.
* src/buffer.c (available_space_after, short_read, flush_archive)
(backspace_output, try_new_volume, simple_flush_read)
(_gnu_flush_read, _gnu_flush_write):
* src/compare.c (read_and_process):
* src/create.c (write_eot, write_gnu_long_link)
(dump_regular_file, dump_dir0):
* src/extract.c (extract_file):
* src/incremen.c (get_gnu_dumpdir):
* src/list.c (read_header):
* src/sparse.c (sparse_dump_region, sparse_extract_region):
* src/system.c (sys_write_archive_buffer)
(sys_child_open_for_compress, sys_child_open_for_uncompress):
* src/update.c (append_file, update_archive):
Use it.
* src/buffer.c (set_next_block_after): Arg is now void *,
not union block *, since it need not be a valid union block * pointer
and this can matter on unusual or debugging implementations.
Turn a loop into an if so that the code is O(1) not O(N).

4 months agoPacify gcc -Wunterminated-string-initialization
Paul Eggert [Thu, 17 Apr 2025 22:13:21 +0000 (15:13 -0700)] 
Pacify gcc -Wunterminated-string-initialization

This diagnostic is new to GCC 15.
* src/create.c (cachedir_file_p): Mark local as nonstring.

5 months agoSync bootstrap from Gnulib
Paul Eggert [Fri, 20 Jun 2025 21:12:33 +0000 (14:12 -0700)] 
Sync bootstrap from Gnulib

5 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Fri, 20 Jun 2025 21:10:42 +0000 (14:10 -0700)] 
build: update gnulib and paxutils submodules to latest

5 months agoPort short_read to UBSan
Paul Eggert [Thu, 12 Jun 2025 07:20:52 +0000 (00:20 -0700)] 
Port short_read to UBSan

Problem reported by Kirill Furman in:
https://lists.gnu.org/r/bug-tar/2025-06/msg00002.html
* src/buffer.c (short_read): Use (char *) record_start,
instead of record_start->buffer, to avoid undefined behavior
accessing past end of buffer.  In practice the undefined
behavior is harmless unless running with -fsanitize=undefined
or a similarly-picky implementation.

5 months agoBugfix
Sergey Poznyakoff [Mon, 2 Jun 2025 04:22:53 +0000 (07:22 +0300)] 
Bugfix

* src/names.c (all_names_found): Exempt wildcard entries from hierarchy
checking.

6 months agoFix spurious "Not found in archive" errors.
Sergey Poznyakoff [Wed, 14 May 2025 12:17:09 +0000 (15:17 +0300)] 
Fix spurious "Not found in archive" errors.

* src/names.c (namelist_match_from): New function.
(namelist_match): Rewrite as a wrapper over it.
(register_match): New function.
(name_match)" Update all possible matches in the name list.

* tests/extrac29.at: New test.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.

6 months agoMinor changes
Sergey Poznyakoff [Tue, 13 May 2025 14:59:15 +0000 (17:59 +0300)] 
Minor changes

6 months agoHandle directory members consistently when listing and when extracting.
Sergey Poznyakoff [Mon, 12 May 2025 14:17:21 +0000 (17:17 +0300)] 
Handle directory members consistently when listing and when extracting.

* src/list.c (skim_member): Recognize directory members using
the same rules as during extraction.
* tests/skipdir.at: New testcase.
* tests/testsuite.at: Add new test.
* tests/Makefile.am: Likewise.

6 months agoFix missing type in mknodat() mode argument
Anssi Hannula [Wed, 6 Nov 2024 10:43:32 +0000 (12:43 +0200)] 
Fix missing type in mknodat() mode argument

Per POSIX, the type of the file to be created should be OR'ed to the
`mode` argument of mknodat().

However, set_xattr() creates an empty file using mknodat() and does not
do that.

E.g. Linux kernel considers zero type as S_IFREG, so the code works on
most systems.

However, e.g. fakeroot, at least up to the current v1.36, does not
consider 0 as S_IFREG, instead creating an invalid file, causing tar to
enter an infinite retry loop when trying to create a file with xattrs
under fakeroot.

Since set_xattr is used only when extracting regular files, fix that
by ORing its mode argument with S_IFREG.

Copyright-paperwork-exempt: Yes

6 months agoFix typos
Tobias Stoeckmann [Mon, 12 May 2025 08:22:52 +0000 (11:22 +0300)] 
Fix typos

Copyright-paperwork-exempt: Yes

6 months agoFix restoring extended attributes from global PAX headers
xiangjingsi [Thu, 8 May 2025 19:53:23 +0000 (22:53 +0300)] 
Fix restoring extended attributes from global PAX headers

Copyright-paperwork-exempt: Yes

6 months agoUpgrade paxutils.
Sergey Poznyakoff [Wed, 7 May 2025 05:33:23 +0000 (08:33 +0300)] 
Upgrade paxutils.

6 months agoFix typo
Sergey Poznyakoff [Tue, 6 May 2025 19:40:02 +0000 (22:40 +0300)] 
Fix typo

6 months agoMinor fix
Sergey Poznyakoff [Tue, 6 May 2025 19:25:38 +0000 (22:25 +0300)] 
Minor fix

* src/extract.c (set_mode): Re-stat the file if current_mode_mask
bits tell so.

6 months agoSkip file or archive member if its transformed name is empty.
Sergey Poznyakoff [Tue, 6 May 2025 12:23:03 +0000 (15:23 +0300)] 
Skip file or archive member if its transformed name is empty.

* NEWS: Document changes.
* doc/tar.texi: Document changes.
* src/common.h (transform_stat_info): Change return value.
(transform_name_fp): Change signature.
(WARN_EMPTY_TRANSFORM): New constant.
* src/create.c: Check return from transform_name.  Skip file, if it
is false.
* src/list.c (transform_stat_info): Return bool.
(read_and): Skip member if transform_stat_info returns false.
* src/transform.c (_transform_name_to_obstack): Change return type.
Always allocate result in obstack.
(transform_name_fp): Change arguments.  Return true on
success (transformed string not empty).  Otherwise return false and
don't change the source string.
* src/warning.c: New warning class: empty-transform.
* tests/extrac17.at: Use --warning=empty-transform.

6 months agoMinor fix
Sergey Poznyakoff [Tue, 6 May 2025 06:39:38 +0000 (09:39 +0300)] 
Minor fix

* src/list.c (transform_stat_info): Modify argument pointer,
not the global variable.

6 months agoPort to recent Gnulib hash_remove
Paul Eggert [Tue, 29 Apr 2025 21:05:59 +0000 (14:05 -0700)] 
Port to recent Gnulib hash_remove

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-tar/2025-04/msg00003.html
* src/incremen.c (remove_directory): hash_delete → hash_remove.

8 months agoFix restoring permissions of intermediate directories with --skip-old-files
Sergey Poznyakoff [Fri, 14 Mar 2025 12:40:36 +0000 (14:40 +0200)] 
Fix restoring permissions of intermediate directories with --skip-old-files

Detailed bug report: https://savannah.gnu.org/bugs/index.php?66774

* src/extract.c (update_interdir_set_stat): New function.
(extract_dir): If the directory already exists, check if it
has been created as intermediate directory earlier.  If so,
update its delayed_set_stat data from archive.

* tests/Makefile.am: Add new testcase.
* tests/testsuite.at: Add new testcase.
* tests/extrac28.at: New file.

8 months agodocumentation: remove incorrect statement
Sergey Poznyakoff [Fri, 14 Mar 2025 07:04:47 +0000 (09:04 +0200)] 
documentation: remove incorrect statement

Reported in https://savannah.gnu.org/bugs/index.php?66704

9 months agodoc: mention timestamp limits
Paul Eggert [Wed, 29 Jan 2025 19:56:04 +0000 (11:56 -0800)] 
doc: mention timestamp limits

10 months agoAdjust to recent Gnulib module renaming
Paul Eggert [Thu, 2 Jan 2025 02:31:40 +0000 (18:31 -0800)] 
Adjust to recent Gnulib module renaming

* gnulib.modules: stdbool was renamed to bool, etc.

10 months agobuild: update gnulib and paxutils submodules to latest
Paul Eggert [Thu, 2 Jan 2025 02:28:22 +0000 (18:28 -0800)] 
build: update gnulib and paxutils submodules to latest

10 months agodoc: fix man page copyright notice
Paul Eggert [Thu, 2 Jan 2025 02:25:43 +0000 (18:25 -0800)] 
doc: fix man page copyright notice

* doc/tar.1: Put copyright notice where the update procedure
will update it properly, and fix it.

10 months agoUpdate copyright years
Paul Eggert [Thu, 2 Jan 2025 02:23:05 +0000 (18:23 -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]*--\(2025 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi

10 months agotests: port to test dirs where `pwd` != `pwd -P`
Paul Eggert [Fri, 27 Dec 2024 22:02:19 +0000 (14:02 -0800)] 
tests: port to test dirs where `pwd` != `pwd -P`

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-tar/2024-12/msg00003.html
* tests/incr08.at: Use pwd -P, not plain pwd.

10 months agotests: port to testing in Linux /tmp
Paul Eggert [Fri, 27 Dec 2024 21:59:03 +0000 (13:59 -0800)] 
tests: port to testing in Linux /tmp

* tests/selnx01.at: Discard restorecon output,
as it contains "Warning no default label for ..."
when run in Linux tmpfs on Fedora 40.

12 months agoFix bad pointer usage in xsparse.c
Paul Eggert [Wed, 6 Nov 2024 18:18:13 +0000 (10:18 -0800)] 
Fix bad pointer usage in xsparse.c

* scripts/xsparse.c (read_xheader): Avoid undefined behavior by
accessing via null pointer sparse_map or out of its bounds when
the input is invalid.  This means we no longer need the ‘expect’
local, so omit it for simplicity.

12 months agoPort xsparse.c to AIX
Paul Eggert [Wed, 6 Nov 2024 18:05:23 +0000 (10:05 -0800)] 
Port xsparse.c to AIX

* scripts/xsparse.c (emalloc): Do not report failure when malloc
(0) returns NULL, as it does on AIX.  Simply return a null
pointer; that’s good enough for xsparse.c.

12 months agoFix xsparse.c big heap allocation bugs
Paul Eggert [Wed, 6 Nov 2024 18:02:02 +0000 (10:02 -0800)] 
Fix xsparse.c big heap allocation bugs

* scripts/xsparse.c (expand_sparse): Read into auto buffer, not heap.
The heap code was wrong for two reasons: it called malloc just once
in the try-again loop, and even when it succeeded it could have
left so few bytes available in the heap that later stdio calls
could fail.  Reading into the auto buffer might be a bit slower
but speed is not an issue here and it’s better to be simple.

12 months agoRemove non-ASCII comment text
Sergey Poznyakoff [Mon, 4 Nov 2024 06:34:29 +0000 (08:34 +0200)] 
Remove non-ASCII comment text

12 months agoUpdate paxutils
Sergey Poznyakoff [Mon, 4 Nov 2024 06:31:28 +0000 (08:31 +0200)] 
Update paxutils

12 months agoAdd LG_BLOCKSIZE to omit some *, % ops
Paul Eggert [Sat, 2 Nov 2024 20:42:02 +0000 (13:42 -0700)] 
Add LG_BLOCKSIZE to omit some *, % ops

* src/buffer.c (_flush_write, short_read, seek_archive)
(_gnu_flush_write):
* src/create.c (write_gnu_long_link, dump_regular_file)
(dump_dir0):
* src/delete.c (write_recent_bytes, flush_file)
(delete_archive_members):
* src/list.c (read_header):
* src/sparse.c (sparse_dump_region, sparse_extract_region)
(pax_dump_header_1):
* src/tar.c (parse_opt):
* src/update.c (append_file):
Prefer shifting and masking to dividing and remaindering by
BLOCKSIZE.  This reclaims some compiler optimizations lost
by our recent preference for signed integers.
* src/tar.h (LG_BLOCKSIZE): New constant, for shifting.

12 months agoImprove sparse I/O performance
Paul Eggert [Sat, 2 Nov 2024 20:06:47 +0000 (13:06 -0700)] 
Improve sparse I/O performance

* src/sparse.c (sparse_dump_region, sparse_extract_region):
Don’t insist on reading and writing sparse files 512
bytes at a time.  This resulted in a 4× to 6× performance
improvement on my platform.

12 months agoSimplify read_incr_db_01 malloc
Paul Eggert [Sat, 2 Nov 2024 18:52:28 +0000 (11:52 -0700)] 
Simplify read_incr_db_01 malloc

* src/incremen.c (read_incr_db_01): Replace arg initbuf with two
args pbuf and pbufsize so that we can simplify memory allocation.
Caller changed.  Omit now-unnecessary free, xstrdup, strlen.

12 months agoAvoid malloc in change_tape_menu
Paul Eggert [Sat, 2 Nov 2024 17:15:03 +0000 (10:15 -0700)] 
Avoid malloc in change_tape_menu

* src/buffer.c (change_tape_menu): Avoid unnecessary xstrdup.

12 months agoImprove common.h comment
Paul Eggert [Sat, 2 Nov 2024 16:54:26 +0000 (09:54 -0700)] 
Improve common.h comment

12 months agoCount short read slop when seeking
Paul Eggert [Sat, 2 Nov 2024 16:54:10 +0000 (09:54 -0700)] 
Count short read slop when seeking

* src/buffer.c (short_read_slop): New static var.
(get_archive_status): Treat anything other than fifos and sockets
as potentially seekable; they’ll tell us if they aren’t, whereas
fifos and sockets cannot be seekable.  Check named files for
initial offset too, to deal with names like /dev/stdin.
Do not worry about start_offset’s value if !seekable_archive,
as it won’t be used.  Use short_read_slop.
(short_read, try_new_volume, simple_flush_read, _gnu_flush_read):
Set short_read_slop.

12 months agoPrefer other types to int in xattrs.c
Paul Eggert [Sat, 2 Nov 2024 06:40:15 +0000 (23:40 -0700)] 
Prefer other types to int in xattrs.c

* src/xattrs.c (xattrs__acls_set) [HAVE_POSIX_ACLS]:
Prefer acl_type_t to int for ACL types.
(acls_get_text, xattrs_acls_get, xattrs_acls_set)
(xattrs_xattrs_get, xattrs_selinux_get, xattrs_selinux_set)
(xattrs_xattrs_set): Prefer bool for booleans.

12 months agoPrever other types to int in warning.c
Paul Eggert [Sat, 2 Nov 2024 06:26:53 +0000 (23:26 -0700)] 
Prever other types to int in warning.c

* src/warning.c (set_warning_option): Prefer bool for boolean.

12 months agoPrefer other types to int in transform.c
Paul Eggert [Sat, 2 Nov 2024 06:24:46 +0000 (23:24 -0700)] 
Prefer other types to int in transform.c

* src/transform.c (add_char_segment, parse_xform_flags)
(parse_transform_expr): Prefer char for char.
(parse_transform_expr): Don’t assume strlen (expr) <= INT_MAX.

12 months agoAvoid unlikely verbose_option overflow
Paul Eggert [Sat, 2 Nov 2024 06:18:30 +0000 (23:18 -0700)] 
Avoid unlikely verbose_option overflow

* src/tar.c (parse_opt, decode_options):
Avoid undefined behavior if verbose_option overflows.

12 months agoPrefer other types to int in system.c
Paul Eggert [Sat, 2 Nov 2024 03:03:53 +0000 (20:03 -0700)] 
Prefer other types to int in system.c

* src/system.c (is_regular_file, sys_exec_setmtime_script):
Prefer bool for boolean.
(sys_exec_command): Prefer char for char.

12 months agoPrefer other types to int in sparse.c
Paul Eggert [Sat, 2 Nov 2024 02:52:50 +0000 (19:52 -0700)] 
Prefer other types to int in sparse.c

* src/sparse.c (oldgnu_get_sparse_info, star_get_sparse_info):
Prefer char for char.

12 months agoPrefer other types to int in names.c
Paul Eggert [Sat, 2 Nov 2024 02:49:02 +0000 (19:49 -0700)] 
Prefer other types to int in names.c

* src/names.c (uname_to_uid, gname_to_gid, handle_option)
(make_file_name): Prefer bool for boolean.
(struct name_elt, read_name_from_file): Prefer char for char.
(handle_option): Invert sense of return value, for clarity.
All uses changed.
(merge_sort_sll, merge_sort, collect_and_sort_names):
Don’t assume list length fits in int.  Use intptr_t not idx_t,
since the bound is the size of all memory rather than one array.

12 months agoPrefer other types to int in misc.c
Paul Eggert [Sat, 2 Nov 2024 02:09:44 +0000 (19:09 -0700)] 
Prefer other types to int in misc.c

* src/misc.c (quote_copy_string, tar_savedir):
Use bool for booleans.  All uses changed.
(quote_copy_string): Use char for chars.
(unquote_string): Return void, since nobody uses return value.
(unquote_string): Check for overflow in escapes like \777.
(wdcache): Now array of idx_t not int, since in theory it
might contain values greater than INT_MAX.  All uses changed.

12 months agoPrefer other types to int in map.c
Paul Eggert [Sat, 2 Nov 2024 01:51:05 +0000 (18:51 -0700)] 
Prefer other types to int in map.c

* src/map.c (map_read): Prefer bool for booleans.
(owner_map_translate, group_map_translate):
Return void, not int, as nobody uses the return value.

12 months agoFix some uses of int in list.c
Paul Eggert [Sat, 2 Nov 2024 01:45:00 +0000 (18:45 -0700)] 
Fix some uses of int in list.c

* src/list.c (decode_xform): Last arg is now int, not a void *
pointer to that int.  All uses changed.
(enforce_one_top_level): Don’t assume string length fits in int.
(transform_stat_info): Prefer char to int for typeflag.
All uses changed.
(decode_header): Prefer bool for booleans.  All uses changed.
(ugswidth): Now idx_t, not int, since in theory it could
exceed INT_MAX.  All uses changed.
(simple_print_header, print_for_mkdir): Don’t assume printf length
fits in int, and similarly for length of user or group name.
* src/transform.c (transform_name_fp): Last arg is now int, not void *.
All uses changed.

12 months agoPrefer other types to int in incremen.c
Paul Eggert [Fri, 1 Nov 2024 21:27:21 +0000 (14:27 -0700)] 
Prefer other types to int in incremen.c

* src/incremen.c (struct dumpdir_iter, dumpdir_first)
(read_incr_db_01, dumpdir_ok, list_dumpdir):
Prefer bool to int for booleans.  All uses changed.
(read_incr_db_01): Don’t assume getline returns <= INT_MAX.
(dumpdir_ok): Prefer char to int for chars.

12 months agoPrefer other types to int in extract.c
Paul Eggert [Fri, 1 Nov 2024 21:15:09 +0000 (14:15 -0700)] 
Prefer other types to int in extract.c

* src/extract.c (fd_chmod, extract_chdir, open_output_file)
(extract_file, extract_link, extract_symlink, extract_node)
(extract_fifo, tar_extractor_t, pepare_to_extract): Prefer char to
int for typeflag, since it’s a char.  All uses changed.
(fd_chmod): Use clearer code for errno.
(extract_dir, extract_file, create_placeholder_file, extract_link)
(extract_symlink, extract_node, extract_fifo, tar_extractor_t):
Return bool true for success, false for failure.  All uses changed.
(open_output_file): Prefer bool for boolean.
(prepare_to_extract): Simplify by returning the extractor a null
pointer, rather than storing through a pointer to an extractor.

12 months agoPrefer other types to int in delete.c
Paul Eggert [Fri, 1 Nov 2024 20:48:53 +0000 (13:48 -0700)] 
Prefer other types to int in delete.c

* src/delete.c (write_record): Arg is bool, not int.
All callers changed.

12 months agoBe a bit more consistent about comparing to zero
Paul Eggert [Fri, 1 Nov 2024 20:44:33 +0000 (13:44 -0700)] 
Be a bit more consistent about comparing to zero

* src/buffer.c (xclose, archive_is_dev, close_archive)
(write_fatal_details, init_volume_number)
(closeout_volume_number, new_volume, try_new_volume):
* src/checkpoint.c (format_checkpoint_string):
* src/compare.c (process_rawdata, diff_file, diff_dumpdir):
* src/create.c (create_archive, restore_parent_fd, dump_file0):
* src/delete.c (delete_archive_members):
* src/exclist.c (cvs_addfn):
* src/extract.c (set_mode, mark_after_links, delay_set_stat)
(repair_delayed_set_stat, make_directories, file_newer_p)
(maybe_recoverable, apply_nonancestor_delayed_set_stat)
(extract_dir, open_output_file, find_delayed_link_source)
(create_placeholder_file, extract_symlink, extract_node)
(extract_fifo, apply_delayed_link):
* src/incremen.c (update_parent_directory, scan_directory)
(read_obstack, read_incr_db_2, write_directory_file)
(try_purge_directory):
* src/map.c (map_read):
* src/misc.c (maybe_backup_file, undo_last_backup, chdir_do)
(tar_savedir):
* src/names.c (handle_file_selection_option, add_file_id)
(handle_option, read_next_name, add_hierarchy_to_namelist)
(collect_and_sort_names):
* src/system.c (run_decompress_program, dec_to_env, time_to_env)
(oct_to_env, str_to_env, chr_to_env, sys_exec_setmtime_script):
* src/tar.c (get_date_or_file, parse_default_options)
(decode_options, main):
* src/unlink.c (flush_deferred_unlinks):
* src/update.c (append_file):
* src/xattrs.c (xattrs__acls_set, xattrs_xattrs_set):
Prefer < 0 when looking at syscalls; prefer != 0 to nothing
when testing an integer in a boolean context.
This is for style, not substance; for example, it’s easier
to read ‘if (wordsplit (...) != WRDSE_OK) ...’ than
‘if (wordsplit (...)) ...’ if you don’t already know that
wordsplit returns an enum rather than bool.
* src/names.c (add_file_id, read_next_name, regex_usage_warning):
* src/transform.c (parse_xform_flags):
Return bool not int, possibly inverting sense so that true means OK.
All callers changed.
* src/tar.c (main): Report errno info if stdopen fails.

12 months agodumpdir_cmp signature
Paul Eggert [Fri, 1 Nov 2024 18:16:19 +0000 (11:16 -0700)] 
dumpdir_cmp signature

* src/compare.c (dumpdir_cmp): Return char, not int.

12 months agoCheck for checkpoint string overflow
Paul Eggert [Fri, 1 Nov 2024 18:04:39 +0000 (11:04 -0700)] 
Check for checkpoint string overflow

It’s very unlikely, but would lead to undefined behavior.
* src/checkpoint.c (format_checkpoint_string): Accept and return
intmax_t, not idx_t.  All callers changed.  Check for integer
overflow by using add_printf.  If overflow occurs, don’t bother
with extending width.

12 months agoPrefer int to idx_t for some small sizes
Paul Eggert [Fri, 1 Nov 2024 17:37:39 +0000 (10:37 -0700)] 
Prefer int to idx_t for some small sizes

* src/create.c (max_octal_val, to_octal, tar_copy_str)
(tar_name_copy_str, to_base256, to_chars_subst, to_chars)
(gid_to_chars, major_to_chars, minor_to_chars, mode_to_chars)
(off_to_chars, time_to_chars, uid_to_chars, string_to_chars)
(split_long_name, write_ustar_long_name, simple_finish_header):
* src/list.c (from_header, gid_from_header, major_from_header)
(minor_from_header, mode_from_header, off_from_header)
(time_from_header, uid_from_header):
Prefer int to idx_t where either will do because the buffer sizes
are known to be small, as this can be a performance win on 32-bit
platforms.  Also, in a few cases the values were negative, whereas
idx_t is supposed to be nonnegative.

12 months agoPacify gcc -Wmissing-variable-declarations
Paul Eggert [Fri, 1 Nov 2024 16:47:18 +0000 (09:47 -0700)] 
Pacify gcc -Wmissing-variable-declarations

* src/buffer.c (start_offset): Now static.