]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Simplify read_header overflow checking
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 31 Jul 2024 00:47:10 +0000 (17:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
* 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.

src/list.c

index caacfd88d80db2b506c175f628a766ace78c2b25..f829f1b86c00ce9ed0c84558d143c299020efa24 100644 (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);