Bug 46075 - FileUpload memory usage
Summary: FileUpload memory usage
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 6.0.18
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-23 03:35 UTC by Richard Wilson
Modified: 2008-11-05 08:09 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Wilson 2008-10-23 03:35:53 UTC
The DefaultFileItem class in pacakge org.apache.tomcat.util.http.fileupload creates a ByteArrayOutputStream of the full threshold size for every control on the submitted form. I have a form with 63 controls (checkboxes, text boxes and one File input), and I set the threshold to 20 Meg to allow upload of large image files into memory. I get an OutOfMemory exception since it tries to allocate 63 lots of 20M, although only 1 control requires the requested size.

I think it would be much more sensible to create the ByteArrayOutputStream with an initial size of only a few kilobytes size it automatically increases its size as data is written to it.
Comment 1 Mark Thomas 2008-10-27 15:43:30 UTC
Thanks for the report. I have applied a patch that uses the default (10k) as an initial size unless the threshold is less than 10k in which case the threshold is used.

The patch has been proposed for 6.0.x
Comment 2 Mark Thomas 2008-11-05 08:09:42 UTC
The patch has been applied to 6.0.x and will be included in 6.0.19 onwards.