]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
paste: fix possible truncated output with large files
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 24 Nov 2014 09:14:44 +0000 (09:14 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 24 Nov 2014 09:31:49 +0000 (09:31 +0000)
If '\n' was present at the size_t boundary of a file,
then that and subsequent data would be discarded.

* src/paste.c (paste_parallel): Avoid the overflow issue
by changing the flag to a boolean rather than a count.
* NEWS: Mention the bug fix.

NEWS
src/paste.c

diff --git a/NEWS b/NEWS
index 2c7e590e080f6eec4fccebd0cdfe40b6fc186da2..27847d429381dfea190bf3cda35acdff90c79028 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   head, od, split, tac, tail, and wc no longer mishandle input from files in
   /proc and /sys file systems that report somewhat-incorrect file sizes.
 
+  paste no longer truncates output for large input files.  This would happen
+  for example with files larger than 4GiB on 32 bit systems with a '\n'
+  character at the 4GiB position.
+  [the bug dates back to the initial implementation]
+
 ** New features
 
   chroot accepts the new --skip-chdir option to not change the working directory
index 2ca75d065924c785f3dbb91250123bad09ff6a19..64c4783e059f2ca4513685821a23be78ce15d2ee 100644 (file)
@@ -235,7 +235,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
         {
           int chr IF_LINT ( = 0);      /* Input character. */
           int err IF_LINT ( = 0);      /* Input errno value.  */
-          size_t line_length = 0;      /* Number of chars in line. */
+          bool sometodo = false;       /* Input chars to process.  */
 
           if (fileptr[i])
             {
@@ -250,7 +250,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
 
               while (chr != EOF)
                 {
-                  line_length++;
+                  sometodo = true;
                   if (chr == '\n')
                     break;
                   xputchar (chr);
@@ -259,7 +259,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
                 }
             }
 
-          if (line_length == 0)
+          if (! sometodo)
             {
               /* EOF, read error, or closed file.
                  If an EOF or error, close the file.  */