split: fail immediately if impossible to create a large file
authorPádraig Brady <P@draigBrady.com>
Sun, 7 Nov 2010 03:09:38 +0000 (03:09 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 16 Nov 2010 00:50:09 +0000 (00:50 +0000)
* src/split.c (main): Error if -[bC] value > OFF_T_MAX
* tests/misc/split-fail: Adjust for the new lower limits

src/split.c
tests/misc/split-fail

index 61ae265..a391ecc 100644 (file)
@@ -432,6 +432,13 @@ main (int argc, char **argv)
               error (0, 0, _("%s: invalid number of bytes"), optarg);
               usage (EXIT_FAILURE);
             }
+          /* If input is a pipe, we could get more data than is possible
+             to write to a single file, so indicate that immediately
+             rather than having possibly future invocations fail.  */
+          if (OFF_T_MAX < n_units)
+            error (EXIT_FAILURE, EFBIG,
+                   _("%s: invalid number of bytes"), optarg);
+
           break;
 
         case 'l':
@@ -456,6 +463,9 @@ main (int argc, char **argv)
               error (0, 0, _("%s: invalid number of bytes"), optarg);
               usage (EXIT_FAILURE);
             }
+          if (OFF_T_MAX < n_units)
+            error (EXIT_FAILURE, EFBIG,
+                   _("%s: invalid number of bytes"), optarg);
           break;
 
         case '0':
index 68c9d73..0ce6f57 100755 (executable)
@@ -45,7 +45,8 @@ split -1 in 2> /dev/null || fail=1
 split -0 in 2> /dev/null && fail=1
 
 split --lines=$UINTMAX_MAX in || fail=1
-split --bytes=$UINTMAX_MAX in || fail=1
+split --bytes=$OFF_T_MAX in || fail=1
+split --line-bytes=$OFF_T_OFLOW 2> /dev/null in && fail=1
 split --line-bytes=$SIZE_OFLOW 2> /dev/null in && fail=1
 
 # Make sure that a huge obsolete option evokes the right failure.