Skip to content

FILEUPLOAD-369: Accept transport padding after a multipart boundary d… - #486

Open
arturobernalg wants to merge 1 commit into
apache:1.xfrom
arturobernalg:FILEUPLOAD-369-transport-padding
Open

arturobernalg wants to merge 1 commit into
apache:1.xfrom
arturobernalg:FILEUPLOAD-369-transport-padding

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

RFC 2046, section 5.1.1 allows a delimiter to be followed by transport padding (SP and HTAB) and requires a receiver to be able to handle it. MultipartStream.readBoundary() only accepted a delimiter directly followed by CRLF or "--". Padding after the first delimiter made the body look as if it had no parts, and padding after any later delimiter caused a MalformedStreamException.

The padding is now skipped after the delimiter. It is still not accepted before the "--" of the close delimiter, since the RFC only allows it after the complete delimiter.

The new tests in MultipartStreamTest cover padding after the first, a later and the close delimiter, and padding before the close marker. Two of them fail without the change. mvn -B -ntp passes (92 tests, checkstyle).

JIRA: https://issues.apache.org/jira/browse/FILEUPLOAD-369

The same code exists in the copy of this class kept in Apache Tomcat, where the maintainers asked for the fix to be made here first.

…elimiter

RFC 2046, section 5.1.1 allows a delimiter to be followed by transport
padding (SP and HTAB) and requires a receiver to handle it. The parser
only accepted a delimiter directly followed by CRLF or "--". Padding after
the first delimiter made the body look as if it had no parts, and padding
after any later delimiter caused a MalformedStreamException. Skip the
padding after the delimiter.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the boundary transport-padding change.

No open issues 🎉

What changed in this PR

Addresses FILEUPLOAD-369 by allowing MultipartStream to handle boundary transport padding as required by RFC 2046.

Changes:

  • Skips spaces and horizontal tabs after a boundary while still rejecting padding before the closing -- marker.
  • Adds regression tests for unpadded boundaries, padded first, intermediate, and closing delimiters, and invalid padding placement.
File Description
src/​test/​java/​org/​apache/​commons/​fileupload/​MultipartStreamTest.java Adds a parsing helper and boundary-padding regression tests.
src/​main/​java/​org/​apache/​commons/​fileupload/​MultipartStream.java Handles transport padding and preserves closing-marker validation.

Review effort: Balanced

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