Subject: [PATCH] tail: fix seeking backward
From: Hannes Braun
Date: Wed, 24 Sep 2025 21:20:49 +0200

* src/tail.c (file_lines): Seek to the previous block instead of the
beginning (or a little before) of the block that was just scanned.
Otherwise, the same block is read and scanned (at least partially)
again. This bug was introduced by commit v9.7-219-g976f8abc1.

I tried to send this on the bug-coreutils mailing list before but I
think it didn't go through. Sorry for any duplicates.

--- ./src/tail.c.orig	2025-09-17 14:34:58.000000000 -0500
+++ ./src/tail.c	2025-09-24 17:39:56.143902640 -0500
@@ -596,7 +596,7 @@
           goto free_buffer;
         }
 
-      pos = xlseek (fd, -bufsize, SEEK_CUR, prettyname);
+      pos = xlseek (fd, -(bufsize + bytes_read), SEEK_CUR, prettyname);
       bytes_read = read (fd, buffer, bufsize);
       if (bytes_read < 0)
         {