Handle enormous record sizes better

Formerly the code could misbehave when the user specified a record
size greater than min (INT_MAX * 512 + 511, PTRDIFF_MAX, SSIZE_MAX).
* src/delete.c (new_blocks, delete_archive_members):
* src/system.c (sys_exec_info_script):
* src/tar.c (blocking_factor, record_size):
Don’t limit blocking factor to INT_MAX.
Prefer signed type for record_size.
Do not exceed IDX_MAX or SSIZE_MAX for record_size;
the SSIZE_MAX limit is needed so that ‘read’ and ‘write’
calls behave sensibly.
This commit is contained in:
Paul Eggert
2024-08-14 23:25:46 -07:00
parent eb9bb9bf80
commit 3ffe2eb073
5 changed files with 17 additions and 15 deletions
+3 -3
View File
@@ -23,7 +23,7 @@
#include <rmt.h>
static union block *new_record;
static int new_blocks;
static idx_t new_blocks;
static bool acting_as_filter;
/* The number of records skipped at the start of the archive, when
@@ -363,11 +363,11 @@ delete_archive_members (void)
/* Write the end of tape. FIXME: we can't use write_eot here,
as it gets confused when the input is at end of file. */
int total_zero_blocks = 0;
idx_t total_zero_blocks = 0;
do
{
int zero_blocks = blocking_factor - new_blocks;
idx_t zero_blocks = blocking_factor - new_blocks;
memset (new_record + new_blocks, 0, BLOCKSIZE * zero_blocks);
total_zero_blocks += zero_blocks;
write_record (total_zero_blocks < 2);