Simplify read_header overflow checking

* src/list.c (read_header): Use ckd_add instead of
doing overflow checking by hand.  Although the old code
was correct on all practical hosts, the new code is simpler
and works even on weird hosts where SIZE_MAX <= INT_MAX.
This commit is contained in:
Paul Eggert
2024-07-30 17:47:10 -07:00
parent 927d67855e
commit 8a3fc52972

View File

@@ -467,14 +467,9 @@ read_header (union block **return_block, struct tar_stat_info *info,
|| header->header.typeflag == GNUTYPE_LONGLINK)
{
union block *header_copy;
size_t name_size = info->stat.st_size;
size_t n = name_size % BLOCKSIZE;
size = name_size + BLOCKSIZE;
if (n)
size += BLOCKSIZE - n;
if (name_size != info->stat.st_size || size < name_size)
if (ckd_add (&size, info->stat.st_size, 2 * BLOCKSIZE - 1))
xalloc_die ();
size -= size % BLOCKSIZE;
header_copy = xmalloc (size + 1);