Repository navigation
[FILEUPLOAD-360] FileUploadBase.getItemIterator(...) does not respect fileCountMax - #483
Open
sharanggupta wants to merge 1 commit into
Open
sharanggupta wants to merge 1 commit into
sharanggupta wants to merge 1 commit into
Conversation
… fileCountMax setFileCountMax(long) was only enforced by parseRequest(RequestContext). The streaming API (getItemIterator) accepted any number of items, so an application that relies on the limit while iterating got no protection. FileItemIteratorImpl now counts the items it hands out and throws FileCountLimitExceededException from hasNext() as soon as the next item would exceed the limit. The check covers plain form-data parts, files nested in a multipart/mixed part and multipart/related parts, and mirrors the 2.x fix (FileItemInputIteratorImpl, apache#481). The four copies of the "item is valid" bookkeeping in findNextItem() are folded into one itemValid(FileItemHeaders) method, which also counts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of the file count limit to the 1.x streaming API (FILEUPLOAD-360, affects 1.5 and 1.6.0).
What
FileUploadBase.setFileCountMax(long)was only enforced byparseRequest(RequestContext). An application that iterates withgetItemIterator(...)(the streaming API) got no limit at all, which is the report in the JIRA ticket. Onmasterthis was fixed for 2.x in #481 (FileItemInputIteratorImpl); 1.x still has the gap.How
FileItemIteratorImplnow counts the items it hands out and throwsFileCountLimitExceededExceptionfromhasNext()as soon as the next item would exceed the limit. It is checked at the same three places as in #481: a plain form-data part, a file nested in amultipart/mixedpart and amultipart/relatedpart.findNextItem()now declaresFileUploadException(it is only called from the constructor andhasNext(), which already declare it). The four copies of the "item is valid" bookkeeping are folded into oneitemValid(FileItemHeaders)method, like #481 did, which is also where the counter is incremented.Behaviour to be aware of
parseRequeststill throwsFileCountLimitExceededExceptionwith the samegetLimit(). Because the iterator now throws first, the exception message forparseRequestcallers changes fromattachment(theATTACHMENTconstantparseRequestpassed as the message) toMaximum file count 2 exceeded.(same wording as 2.x). The old check insideparseRequestis now never reached; I left it in place to keep the diff small and can remove it if you prefer.0now rejects the first item atgetItemIterator(...)time, because the constructor reads the first item (same as 2.x).Tests (
FileUploadTest, run for bothServletFileUploadandPortletFileUpload)multipart/mixedandmultipart/relatedbodies with 3 files and a limit of 2: two items are returned, thenhasNext()throws withgetLimit() == 2;parseRequeststill throws (there was no test for the limit at all in 1.x).Without the change, 6 of the 10 new test executions fail (the three iterator tests, on both implementations); with it all 97 tests pass. Verified locally with the default
mvngoal on Java 17 (0 Checkstyle violations, RAT, Javadoc and japicmp pass) and the test suite on Java 8.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.