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.
This commit is contained in:
Paul Eggert
2026-06-20 00:28:17 -07:00
parent 145a671e8a
commit 67981bbb15
7 changed files with 67 additions and 1 deletions
+6 -1
View File
@@ -1,4 +1,4 @@
GNU tar NEWS - User visible changes. 2026-04-04
GNU tar NEWS - User visible changes. 2026-06-20
Please send GNU tar bug reports to <bug-tar@gnu.org>
version 1.35.90 (git)
@@ -73,6 +73,11 @@ option.
** tar --ignore-failed-read no longer complains about a file removed
before reading.
** tar no longer behaves erratically when reading nonzero size fields
in archive headers representing special files, fifos, and symlinks.
Although these size fields are typically zero, POSIX allows some to
be nonzero, and in practice they do not count data blocks.
* Performance improvements
** Sparse files are now read and written with larger blocksizes.
+1
View File
@@ -39,6 +39,7 @@ Andrey A. Chernov ache@astral.msk.su
Andy Gay andy@rdl.co.uk
Anthony G. Basile blueness@gentoo.org
Antonio Jose Coutinho ajc@di.uminho.pt
Antonio Teixeira antonio.teixeira@suse.com
Ariel Faigon ariel@engr.sgi.com
Arne Wichmann aw@math.uni-sb.de
Arnold Robbins arnold@gnu.org
+16
View File
@@ -535,6 +535,22 @@ read_header (union block **return_block, struct tar_stat_info *info,
struct posix_header const *h = &header->header;
char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
switch (h->typeflag)
{
/* For these file types, although POSIX does not specify the
meaning of the size, it does say there should be no data,
so treat the size as zero. */
case BLKTYPE: case CHRTYPE: case FIFOTYPE:
/* For these file types, POSIX requires that the size be zero.
Be generous and accept any size as zero, as some
nonconforming programs generate nonzero size fields along
with no data. */
case LNKTYPE: case SYMTYPE:
info->stat.st_size = 0;
}
free (recent_long_name);
if (next_long_name)
+1
View File
@@ -143,6 +143,7 @@ TESTSUITE_AT = \
extrac31.at\
extrac32.at\
extrac33.at\
extrac34.at\
filerem01.at\
filerem02.at\
filerem03.at\
+2
View File
@@ -36,11 +36,13 @@ base64 -d < archive.in | xz -c -d > archive.tar
AT_CHECK([tar tf archive.tar],
[0],
[carrier_entry
injected.txt
marker.txt
])
AT_CHECK([tar xvf archive.tar],
[0],
[carrier_entry
injected.txt
marker.txt
])
AT_CLEANUP
+40
View File
@@ -0,0 +1,40 @@
# Check hard link with nonzero size field in tarball. -*- Autotest -*-
# Copyright 2026 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# GNU tar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Check extracting from a nonconforming tarball that has
# a hard link with nonzero size.
AT_SETUP([hard link with a nonzero size field])
AT_KEYWORDS([extract extrac34 hard link])
AT_DATA([archive.in],
[/Td6WFoAAATm1rRGBMBwgFAhARwAAAAAAAAAAAbKrCjgJ/8AaF0AMIAzUBhoiawFdYeRen4lxlj0
QWRLpUM+28ArRsXVY5bGv4H5kijsqiJ4Z9YIVhZd01+IppF+AkltS60aB8fuUW35Tp/3XzUx9Mq2
4ypJFzvcgHXsSIvc9L+mmTDuHzhvJQ/oe7ya8QAASbOfD7CgZcIAAYwBgFAAAEWxohaxxGf7AgAA
AAAEWVo=
])
AT_CHECK([base64 --help >/dev/null 2>&1 || AT_SKIP_TEST
xz --help >/dev/null 2>&1 || AT_SKIP_TEST
base64 -d < archive.in | xz -c -d > archive.tar
])
AT_CHECK([mkdir dir
])
AT_CHECK([tar -C dir -xf archive.tar || exit 1
cmp dir/a dir/b
])
AT_CLEANUP
+1
View File
@@ -360,6 +360,7 @@ m4_include([extrac30.at])
m4_include([extrac31.at])
m4_include([extrac32.at])
m4_include([extrac33.at])
m4_include([extrac34.at])
m4_include([backup01.at])