Skip to content

WW-5874 Bound memory used for multipart form fields by struts.multipart.maxStringLength - #2161

Open
shadowe1ite wants to merge 1 commit into
apache:mainfrom
shadowe1ite:fix/multipart-max-string-length
Open

shadowe1ite wants to merge 1 commit into
apache:mainfrom
shadowe1ite:fix/multipart-max-string-length

Conversation

@shadowe1ite

Copy link
Copy Markdown

Fixes WW-5874

JakartaStreamMultiPartRequest read every form field fully into a ByteArrayOutputStream and built the whole String before checking maxStringLength. So with maxStringLength=10, a 100 KB field was still buffered in full.

The field is now decoded as it's read and only up to maxStringLength characters are kept. The rest of the part is still read so the error can report the real length, but it isn't buffered. The limit is still counted in characters, so multibyte input behaves the same as before.

exceedsMaxStringLength(String, long) is added to AbstractMultiPartRequest, and the existing String overload calls it, so subclasses aren't affected.

Tests cover a 100,000 character field with a limit of 10, multibyte input, and an end to end parse() check that the field is dropped and the error reports the real length. They fail without the fix; all multipart and upload tests in core pass with it.

@lukaszlenart lukaszlenart left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I ran the multipart and upload tests on this branch (JakartaStreamMultiPartRequestTest, JakartaMultiPartRequestTest, ActionFileUploadInterceptorTest), all green, and checked the boundary cases by hand: a field of exactly maxStringLength characters is accepted, one character more is rejected with the real length in the message, and supplementary characters are still counted as two chars, as before.

Three small things before this can go in, details inline:

  1. the one-argument readStream is left without a production caller,
  2. the new protected method needs Javadoc with @since,
  3. the commit headline needs the WW-5874 prefix, the same as the PR title.

We will carry the matching change to support/struts-6-x-x ourselves once this is merged, so there is nothing for you to do on that branch.

@shadowe1ite
shadowe1ite force-pushed the fix/multipart-max-string-length branch from f702283 to a120316 Compare December 3, 2026 11:01
@shadowe1ite

Copy link
Copy Markdown
Author

@lukaszlenart Thanks for the review! Fixed the issues you flagged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants