From: Paul Eggert Date: Sun, 3 Mar 2024 21:17:32 +0000 (-0800) Subject: tar: improve diagnostic for truncated archive X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=21318f385627a30da5d92811dd80f70abbe80ee7;p=thirdparty%2Ftar.git tar: improve diagnostic for truncated archive * src/buffer.c (seek_archive): If EOF has been read, don’t attempt to seek past it. This replaces a bogus "rmtlseek not stopped at a record boundary" message with a better "Unexpected EOF in archive" when I run ‘tar tvf gtar13c.tar’ using the gtar13.tar file here: https://lists.gnu.org/r/bug-tar/2024-03/msg00001.html --- diff --git a/src/buffer.c b/src/buffer.c index 56273642..9da6747a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1072,6 +1072,11 @@ seek_archive (off_t size) off_t start = current_block_ordinal (); off_t offset; off_t nrec, nblk; + + /* If low level I/O is already at EOF, do not try to seek further. */ + if (record_end < record_start + blocking_factor) + return 0; + off_t skipped = (blocking_factor - (current_block - record_start)) * BLOCKSIZE;