tac: handle short reads on input

This can be reproduced by getting the read() above 2G,
which induces a short read, thus triggering the erroneous failure.

  $ truncate -s 5G 5G

  $ cat 5G | TMPDIR=$PWD tac | wc -c
  tac: /tmp/tacFt7txA: read error: Illegal seek
  0

With the fix in place we now get:

  $ cat 5G | TMPDIR=$PWD src/tac | wc -c
  5368709120

* src/tac.c (tac_seekable): Use full_read() to handle short reads.
* NEWS: Mention the bug fix.
Reported at https://bugs.debian.org/1042546
This commit is contained in:
Pádraig Brady 2023-07-31 12:41:26 +01:00
parent a102826245
commit 779f34e180
2 changed files with 6 additions and 1 deletions

4
NEWS
View File

@ -46,6 +46,10 @@ GNU coreutils NEWS -*- outline -*-
'pr --length=1 --double-space' no longer enters an infinite loop.
[This bug was present in "the beginning".]
tac now handles short reads on its input. Previously it may have exited
erroneously, especially with large input files with no separators.
[This bug was present in "the beginning".]
'uptime' no longer incorrectly prints "0 users" on OpenBSD.
[bug introduced in coreutils-9.2]

View File

@ -44,6 +44,7 @@ tac -r -s '.\|
#include <regex.h>
#include "filenamecat.h"
#include "full-read.h"
#include "safe-read.h"
#include "temp-stream.h"
#include "xbinary-io.h"
@ -336,7 +337,7 @@ tac_seekable (int input_fd, char const *file, off_t file_pos)
else
match_start = past_end;
if (safe_read (input_fd, G_buffer, read_size) != read_size)
if (full_read (input_fd, G_buffer, read_size) != read_size)
{
error (0, errno, _("%s: read error"), quotef (file));
return false;