You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/07/22 21:11:17 UTC

httpcomponents-core git commit: [HTTPCORE-539] Constructing a new FileEntityProducer for a file whose length is greater than 2GB throws an IllegalArgumentException.

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 5c38aaaef -> e6fcfd3db


[HTTPCORE-539] Constructing a new FileEntityProducer for a file whose
length is greater than 2GB throws an IllegalArgumentException.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/e6fcfd3d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e6fcfd3d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e6fcfd3d

Branch: refs/heads/master
Commit: e6fcfd3db931a74762ed02d7095c9a4507e218b4
Parents: 5c38aaa
Author: Gary Gregory <ga...@gmail.com>
Authored: Sun Jul 22 15:11:13 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sun Jul 22 15:11:13 2018 -0600

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 ++
 .../http/nio/entity/FileEntityProducer.java     |  2 +-
 .../http/nio/entity/TestFileEntityProducer.java | 57 ++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e6fcfd3d/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 1cbbcd3..a1d12c3 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -21,6 +21,9 @@ adds several incremental improvements.
   
 * HTTPCORE-537: org.apache.hc.core5.http.message.BasicHttpResponse.toString() prints its code twice and no protocol version.
   Contributed by Gary Gregory <ggregory at apache.org>
+  
+* HTTPCORE-539: Constructing a new FileEntityProducer for a file whose length is greater than 2GB throws an IllegalArgumentException.
+  Contributed by Gary Gregory <ggregory at apache.org>
 
 Release 5.0-BETA2
 -------------------

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e6fcfd3d/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
index 8497aaf..da2337a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
@@ -56,7 +56,7 @@ public final class FileEntityProducer implements AsyncEntityProducer {
     public FileEntityProducer(final File file, final int bufferSize, final ContentType contentType) {
         this.file = Args.notNull(file, "File");
         this.length = file.length();
-        this.bytebuf = ByteBuffer.allocate((int)(bufferSize > this.length ? bufferSize : this.length));
+        this.bytebuf = ByteBuffer.allocate(bufferSize);
         this.contentType = contentType;
         this.accessFileRef = new AtomicReference<>(null);
         this.exception = new AtomicReference<>(null);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e6fcfd3d/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestFileEntityProducer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestFileEntityProducer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestFileEntityProducer.java
new file mode 100644
index 0000000..e020e69
--- /dev/null
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestFileEntityProducer.java
@@ -0,0 +1,57 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.nio.entity;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * @since 5.0
+ */
+public class TestFileEntityProducer {
+
+    @ClassRule
+    public static final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    @Test
+    public void testFileLengthMaxIntPlusOne() throws IOException {
+        final File file = tempFolder.newFile("test.bin");
+        try (RandomAccessFile raFile = new RandomAccessFile(file, "rw")) {
+            final long expectedLength = 1L + Integer.MAX_VALUE;
+            raFile.setLength(expectedLength);
+            final FileEntityProducer fileEntityProducer = new FileEntityProducer(file);
+            Assert.assertEquals(expectedLength, fileEntityProducer.getContentLength());
+        }
+    }
+
+}