tar: fix unlikely overflow

* src/delete.c (flush_file): Fix arithmetic overflow if
TYPE_MAXIMUM (off_t) - BLOCKSIZE < current_stat_info.stat.st_size.
This commit is contained in:
Paul Eggert
2024-03-03 13:20:23 -08:00
parent 21318f3856
commit 628c49250a

View File

@@ -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)
{