From: Paul Eggert Date: Sun, 3 Mar 2024 21:20:23 +0000 (-0800) Subject: tar: fix unlikely overflow X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=628c49250ad2257063f35a0780eba847e9ca78c5;p=thirdparty%2Ftar.git tar: fix unlikely overflow * src/delete.c (flush_file): Fix arithmetic overflow if TYPE_MAXIMUM (off_t) - BLOCKSIZE < current_stat_info.stat.st_size. --- diff --git a/src/delete.c b/src/delete.c index 2b46e23b..4808a27b 100644 --- a/src/delete.c +++ b/src/delete.c @@ -139,11 +139,9 @@ write_recent_bytes (char *data, size_t bytes) static void flush_file (void) { - off_t blocks_to_skip; - set_next_block_after (current_header); - blocks_to_skip = (current_stat_info.stat.st_size - + BLOCKSIZE - 1) / BLOCKSIZE; + off_t size = current_stat_info.stat.st_size; + off_t blocks_to_skip = size / BLOCKSIZE + (size % BLOCKSIZE != 0); while (record_end - current_block <= blocks_to_skip) {