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:29:25 -07:00
parent 145a671e8a
commit 67981bbb15
7 changed files with 67 additions and 1 deletions
+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)