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 2007/10/01 22:54:50 UTC

[jira] Created: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

FileItemFactory.setMaxStringLength()
------------------------------------

                 Key: FILEUPLOAD-148
                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
             Project: Commons FileUpload
          Issue Type: New Feature
    Affects Versions: 1.2
            Reporter: Stepan Koltsov


Need method

FileItemFactory.setMaxStringLength(int limitInBytes)

When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").

Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Jochen Wiedmann commented on FILEUPLOAD-148:
--------------------------------------------

> Point is to deny loading large files into memory from FileItem.get() method.

> Point is to deny loading large files into memory from FileItem.get() method.

That's what DiskFileItemFactory.setThreshold() gives you. It seems, you are not using this property or are setting it to a non-sensible value.




> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Stepan Koltsov commented on FILEUPLOAD-148:
-------------------------------------------

No, I want to limit data allowed to be loaded into memory.

I want limit files to 200M and limit size of data in memory to 20K, and I want to avoid explicit checking of getSize() each time before calling getString().

Even better, FileItem.get() should throw exception if file is exceeds some parameter.

Point is to deny loading large files into memory from FileItem.get() method.

Currently, calling of 200M FileItem.get() (or getString()) causes OutOfMemoryError.

> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Stepan Koltsov commented on FILEUPLOAD-148:
-------------------------------------------

Alternatively method

FileItem.getString(int limitInBytes)

can be added.

> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Jochen Wiedmann commented on FILEUPLOAD-148:
--------------------------------------------

Why can't you use the fileSizeMax property?


> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Closed: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Jochen Wiedmann closed FILEUPLOAD-148.
--------------------------------------

    Resolution: Fixed

How about using FileItem.getSize()? Or using a custom FileItemFactory that meets your wished?


> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Stepan Koltsov commented on FILEUPLOAD-148:
-------------------------------------------

fileSizeMax limits size of file on disk. I want limit size of FileItem.getString().

It's OK to have 2Gb file on disk, but result of getString() should be limited to 20K.

> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Stepan Koltsov commented on FILEUPLOAD-148:
-------------------------------------------

I think this functionality would be useful to all users. Because almost nobody checks file.getSize() before calling getString(), so almost any site that uses commons-fileupload can be DOSed by uploading big flie into "text" field.

> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Jochen Wiedmann commented on FILEUPLOAD-148:
--------------------------------------------

Assuming UTF-32, which is the largest encoding I am aware of, you may set fileSizeMax to 4* stringSizeMax and have an effective limit. Ok, that's not a hard limit, because the user might use a more efficient encoding in terms of space, but that should be fine, IMO.


> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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


[jira] Commented: (FILEUPLOAD-148) FileItemFactory.setMaxStringLength()

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

Stepan Koltsov commented on FILEUPLOAD-148:
-------------------------------------------

setThreshold() causes large files to be written on disk. But after files is saved to disk, calling of FileItem.get() loads that large item into memory:

===
public byte[] get() {
    if (isInMemory()) {
        if (cachedContent == null) {
            cachedContent = dfos.getData();
        }
        return cachedContent;
    }

    byte[] fileData = new byte[(int) getSize()];
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(dfos.getFile());
        fis.read(fileData);
    } catch (IOException e) {
        fileData = null;
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    return fileData;
}
===

> FileItemFactory.setMaxStringLength()
> ------------------------------------
>
>                 Key: FILEUPLOAD-148
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-148
>             Project: Commons FileUpload
>          Issue Type: New Feature
>    Affects Versions: 1.2
>            Reporter: Stepan Koltsov
>
> Need method
> FileItemFactory.setMaxStringLength(int limitInBytes)
> When this parameter is set, calling of FileItem.getString() when getSize() exceeds limitInBytes should throw Exception. This is required to avoid OOME in case of wrongly submitted forms (i. e. when bad guy puts big file into the form field "fileDescription").
> Or even better sizeThreshold should be used for this value.

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