Summary: | <multipart-config> is ignored if any of max-file-size/max-request-size/file-threshold-size elements are missing | ||
---|---|---|---|
Product: | Tomcat 8 | Reporter: | Christopher Schultz <chris> |
Component: | Catalina | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 8.5.51 | ||
Target Milestone: | ---- | ||
Hardware: | PC | ||
OS: | Mac OS X 10.1 | ||
Attachments: |
Sample WAR file which reproduces the issue
Proposed patch |
Description
Christopher Schultz
2020-04-27 16:14:06 UTC
Created attachment 37198 [details]
Sample WAR file which reproduces the issue
This WAR file (including source) will work as expected:
1. Deploy the WAR file
2. Navigate to /test which will load index.html
3. Choose an arbitrary file and upload
4a. A small enough file will yield a debug output
4b. A large enough file (> 1MiB) will cause an error
If you edit WEB-INF/web.xml to remove the <file-size-threshold>, you will be able to upload any size file without error.
Ok, ok, the check here looks inaccurate: https://github.com/apache/tomcat/blob/master/java/org/apache/catalina/startup/ContextConfig.java#L1365 Unless all are set, only the location would be used. I think I've found the problem, at ContextConfig:1355: 1355 MultipartDef multipartdef = servlet.getMultipartDef(); 1356 if (multipartdef != null) { 1357 if (multipartdef.getMaxFileSize() != null && 1358 multipartdef.getMaxRequestSize()!= null && 1359 multipartdef.getFileSizeThreshold() != null) { 1360 wrapper.setMultipartConfigElement(new MultipartConfigElement( multipartdef.getLocation(), Long.parseLong(multipartdef.getMaxFileSize()), Long.parseLong(multipartdef.getMaxRequestSize()), Integer.parseInt( multipartdef.getFileSizeThreshold()))); } else { wrapper.setMultipartConfigElement(new MultipartConfigElement( multipartdef.getLocation())); } } When execution reaches 1355, the MultipartDef object contains the expected values: maxFileSize=1048576 maxRequestSize=1049600 fileSizeThreshold=null The predicate on lines 1357 - 1359 cause this configuration to not be applied if any of the items are missing. The servlet spec allows any of these items to be missing, so I believe this is a bug and spec violation together in one. Created attachment 37199 [details]
Proposed patch
Updating description to reflect the fact that any missing element can cause this. Initial testing indicates this patch is correct. I'll commit once I build a proper test-case. My guess is that this will not affect uses of @MultipartConfig annotation, as this bug occurs when copying the web.xml config to the live servlet (wrapper) object. Temporary workaround for anyone observing lack of <multipart-config>: Make sure to specify all of max-file-size, max-request-size, file-size-threshold Fixed in trunk (tc10) in commit 8dddc11512fbd3b91ed9d737a42e4b8415458ddf Working on my git-fu to back-port to other supported branches. Rémy has back-ported to 9.0.x and 8.5.x. |