Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48726
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Feb 2010 23:47:11 +0000 (23:47 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 10 Feb 2010 23:47:11 +0000 (23:47 +0000)
Prevent OOME when uploading large files with the deployer
Patch provided by 'adam'

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@908759 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/ant/AbstractCatalinaTask.java
java/org/apache/catalina/ant/DeployTask.java

index 1954187..d4c8998 100644 (file)
@@ -186,6 +186,8 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
                 if (contentLength >= 0) {
                     hconn.setRequestProperty("Content-Length",
                                              "" + contentLength);
+                    
+                    hconn.setFixedLengthStreamingMode(contentLength);
                 }
             } else {
                 hconn.setDoOutput(false);
index ec1e99b..4231e62 100644 (file)
@@ -167,8 +167,17 @@ public class DeployTask extends AbstractCatalinaTask {
                 }
             } else {
                 try {
-                    stream = new BufferedInputStream
-                        (new FileInputStream(war), 1024);
+                    FileInputStream fsInput = new FileInputStream(war);
+                    long size = fsInput.getChannel().size();
+
+                    if (size > Integer.MAX_VALUE)
+                        throw new UnsupportedOperationException(
+                                "DeployTask does not support WAR files " +
+                                "greater than 2 Gb");
+                    contentLength = (int) size;
+
+                    stream = new BufferedInputStream(fsInput, 1024);
+
                 } catch (IOException e) {
                     throw new BuildException(e);
                 }