On 28/11/16 14:54, Pádraig Brady wrote:
>> FAIL: tests/misc/head-write-error
>> >    =================================
>> >    + diff -u exp err
>> >    --- exp 2016-11-25 22:08:55.826372000 +0000
>> >    +++ err 2016-11-25 22:08:55.842703000 +0000
>> >    @@ -1 +1 @@
>> >    -head: error writing 'standard output'
>> >    +head: 'standard input': cannot seek to offset 65535
>> >    + fail=1
> Hmm, that implies that st->st_size > ST_BLKSIZE(*st)
> for pipes on FreeBSD 11. Maybe we should explicitly
> disallow st_size==0 for the seekable case?
> More generally should we fall back to the nonseekable
> path if the seek fails.
> 
> Also the sed adjustment to the error doesn't seem to be working?
> I.E. I'm surprised to see the ": cannot seek..." portion of the message.
> 
> I'll see can I test on a VM...

Assaf your testing VMs and instructions are awesome!!
http://www.nongnu.org/pretest/

The attached patch fixes the above issue there.

thanks,
Pádraig

>From 5626097534f48f4fa0eb619fc95c77adb6a1019f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 28 Nov 2016 17:11:18 +0000
Subject: [PATCH] head: fix processing of non-seekable input as seekable

* src/head.c (elide_tail_bytes_file): Ensure we don't use
st_size unless we've previously used seek() to determine
the CURRENT_POS in the seekable file.
This was seen to cause issue on FreeBSD 11 when the pipe
buffer was filled with `yes | head --lines=-0`, in which
case st_size was 64KiB while ST_BLKSIZE() was 4KiB.
Reported by Assaf Gordon.
---
 NEWS       | 4 ++++
 src/head.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index e88e932..ea84a4d 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   factor again outputs immediately when numbers are input interactively.
   [bug introduced in coreutils-8.24]
 
+  head no longer tries to process non-seekable input as seekable,
+  which resulted in failures on FreeBSD 11 at least.
+  [bug introduced in coreutils-8.24]
+
   install -DZ and mkdir -pZ now set default SELinux context correctly even if
   two or more directories nested in each other are created and each of them
   defaults to a different SELinux context.
diff --git a/src/head.c b/src/head.c
index 21ace70..756c978 100644
--- a/src/head.c
+++ b/src/head.c
@@ -465,7 +465,7 @@ elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide,
                        struct stat const *st, off_t current_pos)
 {
   off_t size = st->st_size;
-  if (presume_input_pipe || size <= ST_BLKSIZE (*st))
+  if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st))
     return elide_tail_bytes_pipe (filename, fd, n_elide, current_pos);
   else
     {
@@ -754,7 +754,7 @@ elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide,
                        struct stat const *st, off_t current_pos)
 {
   off_t size = st->st_size;
-  if (presume_input_pipe || size <= ST_BLKSIZE (*st))
+  if (presume_input_pipe || current_pos < 0 || size <= ST_BLKSIZE (*st))
     return elide_tail_lines_pipe (filename, fd, n_elide, current_pos);
   else
     {
-- 
2.5.5

Reply via email to