You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Stepan Koltsov (JIRA)" <ji...@apache.org> on 2008/05/29 13:48:45 UTC

[jira] Created: (FILEUPLOAD-160) disk leak if multipart parse error

disk leak if multipart parse error
----------------------------------

                 Key: FILEUPLOAD-160
                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-160
             Project: Commons FileUpload
          Issue Type: Bug
            Reporter: Stepan Koltsov


FleUploadBase.parseRequest() keeps files on disk if parser error occured. Patch

{code}
diff -r cf24bc636e09 -r f706d95f56b7 src/java/org/apache/commons/fileupload/FileUploadBase.java
--- a/src/java/org/apache/commons/fileupload/FileUploadBase.java	Wed May 28 22:25:00 2008 +0400
+++ b/src/java/org/apache/commons/fileupload/FileUploadBase.java	Thu May 29 15:40:04 2008 +0400
@@ -345,9 +345,10 @@
      */
     public List /* FileItem */ parseRequest(RequestContext ctx)
             throws FileUploadException {
+        List items = new ArrayList();
+        boolean successful = false;
         try {
             FileItemIterator iter = getItemIterator(ctx);
-            List items = new ArrayList();
             FileItemFactory fac = getFileItemFactory();
             if (fac == null) {
                 throw new NullPointerException(
@@ -358,6 +359,7 @@
                 FileItem fileItem = fac.createItem(item.getFieldName(),
                         item.getContentType(), item.isFormField(),
                         item.getName());
+                items.add(fileItem);
                 try {
                     Streams.copy(item.openStream(), fileItem.getOutputStream(),
                             true);
@@ -372,13 +374,24 @@
                     final FileItemHeaders fih = item.getHeaders();
                     ((FileItemHeadersSupport) fileItem).setHeaders(fih);
                 }
-                items.add(fileItem);
             }
+            successful = true;
             return items;
         } catch (FileUploadIOException e) {
             throw (FileUploadException) e.getCause();
         } catch (IOException e) {
             throw new FileUploadException(e.getMessage(), e);
+        } finally {
+            if (!successful) {
+                for (Iterator iterator = items.iterator(); iterator.hasNext();) {
+                    FileItem fileItem = (FileItem) iterator.next();
+                    try {
+                        fileItem.delete();
+                    } catch (Throwable e) {
+                        // ignore it
+                    }
+                }
+            }
         }
     }
 
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (FILEUPLOAD-160) disk leak if multipart parse error

Posted by "Jochen Wiedmann (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FILEUPLOAD-160?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jochen Wiedmann resolved FILEUPLOAD-160.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.3
         Assignee: Jochen Wiedmann

Applied, thank you!


> disk leak if multipart parse error
> ----------------------------------
>
>                 Key: FILEUPLOAD-160
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-160
>             Project: Commons FileUpload
>          Issue Type: Bug
>            Reporter: Stepan Koltsov
>            Assignee: Jochen Wiedmann
>             Fix For: 1.3
>
>
> FleUploadBase.parseRequest() keeps files on disk if parser error occured. Patch
> {code}
> diff -r cf24bc636e09 -r f706d95f56b7 src/java/org/apache/commons/fileupload/FileUploadBase.java
> --- a/src/java/org/apache/commons/fileupload/FileUploadBase.java	Wed May 28 22:25:00 2008 +0400
> +++ b/src/java/org/apache/commons/fileupload/FileUploadBase.java	Thu May 29 15:40:04 2008 +0400
> @@ -345,9 +345,10 @@
>       */
>      public List /* FileItem */ parseRequest(RequestContext ctx)
>              throws FileUploadException {
> +        List items = new ArrayList();
> +        boolean successful = false;
>          try {
>              FileItemIterator iter = getItemIterator(ctx);
> -            List items = new ArrayList();
>              FileItemFactory fac = getFileItemFactory();
>              if (fac == null) {
>                  throw new NullPointerException(
> @@ -358,6 +359,7 @@
>                  FileItem fileItem = fac.createItem(item.getFieldName(),
>                          item.getContentType(), item.isFormField(),
>                          item.getName());
> +                items.add(fileItem);
>                  try {
>                      Streams.copy(item.openStream(), fileItem.getOutputStream(),
>                              true);
> @@ -372,13 +374,24 @@
>                      final FileItemHeaders fih = item.getHeaders();
>                      ((FileItemHeadersSupport) fileItem).setHeaders(fih);
>                  }
> -                items.add(fileItem);
>              }
> +            successful = true;
>              return items;
>          } catch (FileUploadIOException e) {
>              throw (FileUploadException) e.getCause();
>          } catch (IOException e) {
>              throw new FileUploadException(e.getMessage(), e);
> +        } finally {
> +            if (!successful) {
> +                for (Iterator iterator = items.iterator(); iterator.hasNext();) {
> +                    FileItem fileItem = (FileItem) iterator.next();
> +                    try {
> +                        fileItem.delete();
> +                    } catch (Throwable e) {
> +                        // ignore it
> +                    }
> +                }
> +            }
>          }
>      }
>  
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (FILEUPLOAD-160) disk leak if multipart parse error

Posted by "Stepan Koltsov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FILEUPLOAD-160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12633823#action_12633823 ] 

Stepan Koltsov commented on FILEUPLOAD-160:
-------------------------------------------

Hello!

> disk leak if multipart parse error
> ----------------------------------
>
>                 Key: FILEUPLOAD-160
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-160
>             Project: Commons FileUpload
>          Issue Type: Bug
>            Reporter: Stepan Koltsov
>
> FleUploadBase.parseRequest() keeps files on disk if parser error occured. Patch
> {code}
> diff -r cf24bc636e09 -r f706d95f56b7 src/java/org/apache/commons/fileupload/FileUploadBase.java
> --- a/src/java/org/apache/commons/fileupload/FileUploadBase.java	Wed May 28 22:25:00 2008 +0400
> +++ b/src/java/org/apache/commons/fileupload/FileUploadBase.java	Thu May 29 15:40:04 2008 +0400
> @@ -345,9 +345,10 @@
>       */
>      public List /* FileItem */ parseRequest(RequestContext ctx)
>              throws FileUploadException {
> +        List items = new ArrayList();
> +        boolean successful = false;
>          try {
>              FileItemIterator iter = getItemIterator(ctx);
> -            List items = new ArrayList();
>              FileItemFactory fac = getFileItemFactory();
>              if (fac == null) {
>                  throw new NullPointerException(
> @@ -358,6 +359,7 @@
>                  FileItem fileItem = fac.createItem(item.getFieldName(),
>                          item.getContentType(), item.isFormField(),
>                          item.getName());
> +                items.add(fileItem);
>                  try {
>                      Streams.copy(item.openStream(), fileItem.getOutputStream(),
>                              true);
> @@ -372,13 +374,24 @@
>                      final FileItemHeaders fih = item.getHeaders();
>                      ((FileItemHeadersSupport) fileItem).setHeaders(fih);
>                  }
> -                items.add(fileItem);
>              }
> +            successful = true;
>              return items;
>          } catch (FileUploadIOException e) {
>              throw (FileUploadException) e.getCause();
>          } catch (IOException e) {
>              throw new FileUploadException(e.getMessage(), e);
> +        } finally {
> +            if (!successful) {
> +                for (Iterator iterator = items.iterator(); iterator.hasNext();) {
> +                    FileItem fileItem = (FileItem) iterator.next();
> +                    try {
> +                        fileItem.delete();
> +                    } catch (Throwable e) {
> +                        // ignore it
> +                    }
> +                }
> +            }
>          }
>      }
>  
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.