Collin Funk <[email protected]> writes: > Here are some simple reproducers for the two semi-related bugs: > > $ head -c $((1024 * 1024 + 8192 + 1)) /dev/zero \ > | head -c -$((1024 * 1024 + 8192)) | wc -c > 8193 > $ head -c $((1024 * 1024 + 8192 + 1)) /dev/zero \ > | head -c -$((1024 * 1024 + 8192 + 2)) | wc -c > head: error writing 'standard output' > 0 > > -- 8< -- > > * src/head.c (elide_tail_bytes_pipe): Don't set REM to BUFSIZ when the > REMAINDER is zero. Don't assume the input is longer than the given > number of bytes. > * tests/head/head-elide-tail.pl ($HEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD) > ($MULTIPLE, $FRACTION): New variables. > (@Tests): Add a few test cases for the bugs. > * NEWS: Mention the bug fixes. > > Discovered by Anthropic's OSS Scanner, as bug ANT-2026-BMLRFV62. > --- > NEWS | 8 ++++++++ > src/head.c | 4 ++-- > tests/head/head-elide-tail.pl | 29 ++++++++++++++++++++++++++++- > 3 files changed, 38 insertions(+), 3 deletions(-)
Oops. This patch depends on the attached patch, which I forgot to send. Collin
>From a66fa640208986675331b51983bd091203c3d09a Mon Sep 17 00:00:00 2001 Message-ID: <a66fa640208986675331b51983bd091203c3d09a.1794806777.git.collin.fu...@gmail.com> From: Collin Funk <[email protected]> Date: Sun, 15 Nov 2026 19:47:16 -0800 Subject: [PATCH 1/2] tests: head: set READ_BUFSIZE to BUFSIZ as done in src/head.c * src/getlimits.c (main): Print the value of BUFSIZ. * tests/head/head-elide-tail.pl ($limits): Save the results of getlimits. ($READ_BUFSIZE): Set it to the value of BUFSIZ. --- src/getlimits.c | 1 + tests/head/head-elide-tail.pl | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/getlimits.c b/src/getlimits.c index 69d19c67e..b291c8b81 100644 --- a/src/getlimits.c +++ b/src/getlimits.c @@ -203,6 +203,7 @@ main (int argc, char **argv) /* Other useful constants */ printf ("SIGRTMIN=%jd\n", (intmax_t) {SIGRTMIN}); printf ("SIGRTMAX=%jd\n", (intmax_t) {SIGRTMAX}); + printf ("BUFSIZ=%ju\n", (uintmax_t) {BUFSIZ}); printf ("IO_BUFSIZE=%ju\n", (uintmax_t) {IO_BUFSIZE}); /* Errnos */ diff --git a/tests/head/head-elide-tail.pl b/tests/head/head-elide-tail.pl index 7ec02c267..4ffdcb1a2 100755 --- a/tests/head/head-elide-tail.pl +++ b/tests/head/head-elide-tail.pl @@ -26,7 +26,8 @@ $ENV{PROG} = 'head'; @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; # This should match the definition in head.c. -my $READ_BUFSIZE = 8192; +my $limits = getlimits (); +my $READ_BUFSIZE = $limits->{BUFSIZ}; my @Tests = ( -- 2.56.1
