]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
tar: fix unlikely overflow
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Mar 2024 21:20:23 +0000 (13:20 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 3 Mar 2024 21:28:23 +0000 (13:28 -0800)
* src/delete.c (flush_file): Fix arithmetic overflow if
TYPE_MAXIMUM (off_t) - BLOCKSIZE < current_stat_info.stat.st_size.

src/delete.c

index 2b46e23bb3bfde46dc7e5d41e4b454cdcb05c7a9..4808a27be507379b2cef248215ba96f68c04b94c 100644 (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)
     {