You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/05/04 04:06:01 UTC

commons-compress git commit: COMPRESS-451 reject 0 buffersize in IOUtils.copy

Repository: commons-compress
Updated Branches:
  refs/heads/master ff10aeaaf -> 0aeda4fcc


COMPRESS-451 reject 0 buffersize in IOUtils.copy


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0aeda4fc
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0aeda4fc
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0aeda4fc

Branch: refs/heads/master
Commit: 0aeda4fcc3c6de7109acd8cf78f8779654b9f771
Parents: ff10aea
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri May 4 06:05:29 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri May 4 06:05:29 2018 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                                       | 3 +++
 src/main/java/org/apache/commons/compress/utils/IOUtils.java  | 7 ++++++-
 .../java/org/apache/commons/compress/utils/IOUtilsTest.java   | 6 ++++++
 3 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0aeda4fc/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 61c1279..37da29a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -78,6 +78,9 @@ The <action> type attribute can be add,update,fix,remove.
         Add a new SkipShieldingInputStream class that can be used wit
         streams that throw an IOException whne skip is invoked.
       </action>
+      <action issue="COMPRESS-451" type="fix" date="2018-05-04">
+        IOUtils.copy now verifies the buffer size is bigger than 0.
+      </action>
     </release>
     <release version="1.16.1" date="2018-02-10"
              description="Release 1.16.1">

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0aeda4fc/src/main/java/org/apache/commons/compress/utils/IOUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/utils/IOUtils.java b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
index c7e0e80..50577c9 100644
--- a/src/main/java/org/apache/commons/compress/utils/IOUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
@@ -68,12 +68,17 @@ public final class IOUtils {
      * @param output
      *            the target Stream
      * @param buffersize
-     *            the buffer size to use
+     *            the buffer size to use, must be bigger than 0
      * @return the number of bytes copied
      * @throws IOException
      *             if an error occurs
+     * @throws IllegalArgumentException
+     *             if buffersize is smaller than or equal to 0
      */
     public static long copy(final InputStream input, final OutputStream output, final int buffersize) throws IOException {
+        if (buffersize < 1) {
+            throw new IllegalArgumentException("buffersize must be bigger than 0");
+        }
         final byte[] buffer = new byte[buffersize];
         int n = 0;
         long count=0;

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0aeda4fc/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
index 2bba435..fce779e 100644
--- a/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/IOUtilsTest.java
@@ -18,6 +18,7 @@
 package org.apache.commons.compress.utils;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.EOFException;
 import java.io.FilterInputStream;
 import java.io.InputStream;
@@ -101,6 +102,11 @@ public class IOUtilsTest {
         readFully(source, b);
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void copyThrowsOnZeroBufferSize() throws IOException {
+        IOUtils.copy(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream(), 0);
+    }
+
     private static void readFully(final byte[] source, ByteBuffer b) throws IOException {
         IOUtils.readFully(new ReadableByteChannel() {
                 private int idx;