Repository navigation
WW-5873 Enforce struts.multipart.maxSizeOfFiles in both multipart parsers - #2160
shadowe1ite wants to merge 1 commit into
Conversation
lukaszlenart
left a comment
There was a problem hiding this comment.
Thanks for this, moving the check into AbstractMultiPartRequest and bounding the streamed write is the right shape. A few things before it can go in:
1. A negative maxSizeOfFiles should mean "no limit"
exceedsMaxSizeOfFiles checks fileSize <= maxSizeOfFiles - currentFilesSize, so with struts.multipart.maxSizeOfFiles=-1 every non-empty file is now rejected by JakartaMultiPartRequest, which used to ignore the setting entirely. The other multipart limits already treat a negative value as unlimited (maxFiles and maxParameterCount in AbstractMultiPartRequest), and the upload docs say the max options can be set to unlimited with -1. Please apply the same convention in both parsers (in the stream parser, take the unbounded path) and add a test with -1.
2. Route every write through the three-arg streamFileToDisk and deprecate the two-arg one
When maxSizeOfFiles is set, processFileItemAsFileField calls the three-arg overload directly, so a subclass that overrides streamFileToDisk(FileItemInput, File) silently loses its hook exactly when the limit is configured. Please always call streamFileToDisk(fileItemInput, file, maxBytes) (passing Long.MAX_VALUE when there is no limit), and mark the two-arg overload @Deprecated(since = "7.6.0", forRemoval = true) with a Javadoc pointer to the new one. Its removal will be tracked separately for 8.0.0.
3. Commit headline
The commit is headlined Enforce struts.multipart.maxSizeOfFiles in both multipart parsers; please prefix it with WW-5873, e.g. WW-5873 fix(core): enforce struts.multipart.maxSizeOfFiles in both multipart parsers.
4. Javadoc on addMaxSizeOfFilesError
It's a new protected method and its neighbours carry a Javadoc; a one-liner is enough.
The rest looks good: the early return leaves the remaining part to fileupload2, which closes the current item before moving on, actualSizeOfUploadedFiles keeps its signature after the move, and the tests run against both parsers through AbstractMultiPartRequestTest.
939169d to
614e9e7
Compare
@lukaszlenart Thanks for the review! Fixed all four points and added a -1 test for both parsers. All 92 multipart tests pass. |
Fixes WW-5873
struts.multipart.maxSizeOfFileswasn't really enforced.JakartaMultiPartRequestnever checked it, andJakartaStreamMultiPartRequestonly checked it after the whole file was already on disk.The check now lives in
AbstractMultiPartRequestand both parsers use it. The streaming parser stops writing as soon as the remaining budget is used up and deletes the partial file. The old two-argstreamFileToDiskis still there for subclasses.One small behavior change: a total exactly equal to the limit is now accepted. The streaming parser used to reject it because it compared with
>=.The default parser still lets commons-fileupload parse the whole request first, so what it buffers is still bounded by
struts.multipart.maxSize, same as before.Tests for both parsers (single file over the limit, a second file crossing it, files exactly at the limit) plus one for the streaming parser checking that a 1 MB upload with a 10 byte limit writes no more than 10 bytes. 4 of them fail without the fix; all multipart and upload tests in core pass with it.