From 8a3fc529729acf38276b27f6b7bc50962dfab799 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 30 Jul 2024 17:47:10 -0700 Subject: [PATCH] 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. --- src/list.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/list.c b/src/list.c index caacfd88..f829f1b8 100644 --- a/src/list.c +++ b/src/list.c @@ -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); -- 2.47.2