Bug#1042546: tac: /tmp/tac...: read error: Illegal seek

2023-07-31 Thread Pádraig Brady

On 30/07/2023 20:30, наб wrote:

On Sun, Jul 30, 2023 at 12:14:10PM +0100, Pádraig Brady wrote:

On 30/07/2023 05:09, наб wrote:

$ truncate -s 5G 5G
$ cat 5G | /bin/tac | wc -c
/bin/tac: /tmp/tacOOOwnf: read error: Illegal seek
0

Couldn't repo with 64 bit tac 9.1

Tested on amd64.


or 32 bit tac latest

I just get the expected:

$ cat 5G | git/coreutils/src/tac | wc -c
git/coreutils/src/tac: /tmp/cutmpZRrn27: write error: No space left on device

Well, what if you let /tmp grow enough to allocate the 5G
(or put it on a compressed filesystem that'll discard the zeroes)?
I ran this on a big system so my /tmp has 47G avail,
but I can reproduce your lack of reproduction by making it too small:

# mount -t tmpfs -o size=1g tmpfs dir
$ cat 5G | TMPDIR=dir /bin/tac | wc -c
/bin/tac: dir/tacbIeNII: write error: No space left on device
0


Indeed.
I'm addressing this upstream with the attached.

cheers,
Pádraig
From ef60e3727ee4e4e5c3232a2f44a4f8ef9681aaba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= 
Date: Mon, 31 Jul 2023 12:41:26 +0100
Subject: [PATCH] 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
---
 NEWS  | 4 
 src/tac.c | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 92e591ee2..011058299 100644
--- a/NEWS
+++ b/NEWS
@@ -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".]
+
   'wc -l' and 'cksum' no longer crash with an "Illegal instruction" error
   on x86 Linux kernels that disable XSAVE YMM.  This was seen on Xen VMs.
   [bug introduced in coreutils-9.0]
diff --git a/src/tac.c b/src/tac.c
index 285f99a74..4c3655895 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -44,6 +44,7 @@ tac -r -s '.\|
 #include 
 
 #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;
-- 
2.41.0



Bug#1042546: tac: /tmp/tac...: read error: Illegal seek

2023-07-30 Thread наб
On Sun, Jul 30, 2023 at 12:14:10PM +0100, Pádraig Brady wrote:
> On 30/07/2023 05:09, наб wrote:
> > $ truncate -s 5G 5G
> > $ cat 5G | /bin/tac | wc -c
> > /bin/tac: /tmp/tacOOOwnf: read error: Illegal seek
> > 0
> Couldn't repo with 64 bit tac 9.1
Tested on amd64.

> or 32 bit tac latest
> 
> I just get the expected:
> 
> $ cat 5G | git/coreutils/src/tac | wc -c
> git/coreutils/src/tac: /tmp/cutmpZRrn27: write error: No space left on device
Well, what if you let /tmp grow enough to allocate the 5G
(or put it on a compressed filesystem that'll discard the zeroes)?
I ran this on a big system so my /tmp has 47G avail,
but I can reproduce your lack of reproduction by making it too small:

# mount -t tmpfs -o size=1g tmpfs dir
$ cat 5G | TMPDIR=dir /bin/tac | wc -c
/bin/tac: dir/tacbIeNII: write error: No space left on device
0

Best,
наб


signature.asc
Description: PGP signature


Bug#1042546: tac: /tmp/tac...: read error: Illegal seek

2023-07-30 Thread Pádraig Brady

On 30/07/2023 05:09, наб wrote:

Package: coreutils
Version: 9.1-1
Severity: normal

Dear Maintainer,

$ truncate -s 5G 5G
$ cat 5G | /bin/tac | wc -c
/bin/tac: /tmp/tacOOOwnf: read error: Illegal seek
0

наб

-- System Information:
Debian Release: 12.1
   APT prefers stable-updates
   APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386


Couldn't repo with 64 bit tac 9.1
or 32 bit tac latest

I just get the expected:

$ cat 5G | git/coreutils/src/tac | wc -c
git/coreutils/src/tac: /tmp/cutmpZRrn27: write error: No space left on device

cheers,
Pádraig



Bug#1042546: tac: /tmp/tac...: read error: Illegal seek

2023-07-29 Thread наб
Package: coreutils
Version: 9.1-1
Severity: normal

Dear Maintainer,

$ truncate -s 5G 5G
$ cat 5G | /bin/tac | wc -c
/bin/tac: /tmp/tacOOOwnf: read error: Illegal seek
0

наб

-- System Information:
Debian Release: 12.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable-debug'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.1.0-9-amd64 (SMP w/24 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, 
TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages coreutils depends on:
ii  libacl1  2.3.1-3
ii  libattr1 1:2.5.1-4
ii  libc62.36-9+deb12u1
ii  libgmp10 2:6.2.1+dfsg1-1.1
ii  libselinux1  3.4-1+b6

coreutils recommends no packages.

coreutils suggests no packages.

-- no debconf information


signature.asc
Description: PGP signature