bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: shuf off-by-one bug led to infloop


From: Jim Meyering
Subject: FYI: shuf off-by-one bug led to infloop
Date: Fri, 29 Sep 2006 18:41:28 +0200

I stumbled across this one today:

2006-09-29  Jim Meyering  <address@hidden>

        * src/shuf.c (read_input): Fix an off-by-one error that
        would cause an infloop for piped input of 8KB or more.
        * NEWS: Mention the fix.
        * tests/misc/shuf: Test for the above fix.

Index: src/shuf.c
===================================================================
RCS file: /fetish/cu/src/shuf.c,v
retrieving revision 1.3
diff -u -r1.3 shuf.c
--- src/shuf.c  18 Sep 2006 20:38:54 -0000      1.3
+++ src/shuf.c  29 Sep 2006 16:27:36 -0000
@@ -178,7 +178,7 @@

   do
     {
-      if (alloc == used)
+      if (alloc <= used + 1)
        {
          if (alloc == SIZE_MAX)
            xalloc_die ();
Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.432
diff -u -r1.432 NEWS
--- NEWS        29 Sep 2006 09:54:24 -0000      1.432
+++ NEWS        29 Sep 2006 16:37:53 -0000
@@ -35,6 +35,9 @@

     "groups" now processes options like --help more compatibly.

+  shuf would infloop, given 8KB or more of piped input
+
+
 * Major changes in release 6.2 (2006-09-18) [stable candidate]

 ** Changes in behavior
Index: tests/misc/shuf
===================================================================
RCS file: /fetish/cu/tests/misc/shuf,v
retrieving revision 1.2
diff -u -r1.2 shuf
--- tests/misc/shuf     17 Aug 2006 19:58:32 -0000      1.2
+++ tests/misc/shuf     29 Sep 2006 16:38:56 -0000
@@ -51,4 +51,8 @@
 sort -n out > out1
 cmp in out1 || { fail=1; echo "not a permutation" 1>&2; }

+# Before coreutils-6.3, this would infloop.
+# "seq 1860" produces 8193 bytes of output.
+seq 1860 | shuf > /dev/null || fail=1
+
 (exit $fail); exit $fail




reply via email to

[Prev in Thread] Current Thread [Next in Thread]