commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1568866 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/FileUploadBase.java
Date Mon, 17 Feb 2014 00:13:00 GMT
Author: sebb
Date: Mon Feb 17 00:13:00 2014
New Revision: 1568866

URL: http://svn.apache.org/r1568866
Log:
FILEUPLOAD-250 FileUploadBase - potential resource leak - InputStream not closed on exception

Modified:
    commons/proper/fileupload/trunk/src/changes/changes.xml
    commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java

Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568866&r1=1568865&r2=1568866&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/changes/changes.xml (original)
+++ commons/proper/fileupload/trunk/src/changes/changes.xml Mon Feb 17 00:13:00 2014
@@ -45,6 +45,7 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.4" date="TBA" description=
 "TBA">
+      <action issue="FILEUPLOAD-250" dev="sebb" type="fix">FileUploadBase - potential
resource leak - InputStream not closed on exception</action>
       <action issue="FILEUPLOAD-244" dev="sebb" type="fix">DiskFileItem.readObject
fails to close FileInputStream</action>
       <action issue="FILEUPLOAD-246" dev="sebb" type="update">FileUpload should use
IOUtils.closeQuietly where relevant</action>
       <action issue="FILEUPLOAD-245" dev="sebb" type="fix">DiskFileItem.get() may not
fully read the data</action>

Modified: commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java?rev=1568866&r1=1568865&r2=1568866&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java
(original)
+++ commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/FileUploadBase.java
Mon Feb 17 00:13:00 2014
@@ -38,6 +38,7 @@ import org.apache.commons.fileupload.uti
 import org.apache.commons.fileupload.util.FileItemHeadersImpl;
 import org.apache.commons.fileupload.util.LimitedInputStream;
 import org.apache.commons.fileupload.util.Streams;
+import org.apache.commons.io.IOUtils;
 
 /**
  * <p>High level API for processing file uploads.</p>
@@ -949,7 +950,6 @@ public abstract class FileUploadBase {
                                MULTIPART_FORM_DATA, MULTIPART_MIXED, contentType));
             }
 
-            InputStream input = ctx.getInputStream();
 
             @SuppressWarnings("deprecation") // still has to be backward compatible
             final int contentLengthInt = ctx.getContentLength();
@@ -960,6 +960,7 @@ public abstract class FileUploadBase {
                                      : contentLengthInt;
                                      // CHECKSTYLE:ON
 
+            InputStream input; // N.B. this is eventually closed in MultipartStream processing
             if (sizeMax >= 0) {
                 if (requestSize != -1 && requestSize > sizeMax) {
                     throw new SizeLimitExceededException(
@@ -967,7 +968,8 @@ public abstract class FileUploadBase {
                                 Long.valueOf(requestSize), Long.valueOf(sizeMax)),
                                requestSize, sizeMax);
                 }
-                input = new LimitedInputStream(input, sizeMax) {
+                // N.B. this is eventually closed in MultipartStream processing
+                input = new LimitedInputStream(ctx.getInputStream(), sizeMax) {
                     @Override
                     protected void raiseError(long pSizeMax, long pCount)
                             throws IOException {
@@ -978,6 +980,8 @@ public abstract class FileUploadBase {
                         throw new FileUploadIOException(ex);
                     }
                 };
+            } else {
+                input = ctx.getInputStream();
             }
 
             String charEncoding = headerEncoding;
@@ -987,6 +991,7 @@ public abstract class FileUploadBase {
 
             boundary = getBoundary(contentType);
             if (boundary == null) {
+                IOUtils.closeQuietly(input); // avoid possible resource leak
                 throw new FileUploadException("the request was rejected because no multipart
boundary was found");
             }
 
@@ -994,6 +999,7 @@ public abstract class FileUploadBase {
             try {
                 multi = new MultipartStream(input, boundary, notifier);
             } catch (IllegalArgumentException iae) {
+                IOUtils.closeQuietly(input); // avoid possible resource leak
                 throw new InvalidContentTypeException(
                         format("The boundary specified in the %s header is too long", CONTENT_TYPE),
iae);
             }



Mime
View raw message