Skip to content

Reject truncated percent-encoding in RFC2231Utility.decodeText#477

Merged
garydgregory merged 1 commit into
apache:1.xfrom
alhudz:rfc2231-truncated-pct-1.x
Jul 13, 2026
Merged

Reject truncated percent-encoding in RFC2231Utility.decodeText#477
garydgregory merged 1 commit into
apache:1.xfrom
alhudz:rfc2231-truncated-pct-1.x

Conversation

@alhudz

@alhudz alhudz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Port of #475 to 1.x, as requested there. Same change as merged on master, adapted to RFC2231Utility.

Repro: RFC2231Utility.decodeText("UTF-8''report%3") (a truncated RFC 5987 percent escape, reachable via filename*).
Expected: rejected, the same as %GG or a non-ASCII byte already are.
Actual: returns report; fromHex treats a % with fewer than two following characters as end-of-input and drops the truncated escape.
Fix: throw IllegalArgumentException, matching the other malformed-input paths in fromHex. Covered by a new case in RFC2231UtilityTestCase; full suite passes on 1.x (86 tests, 0 failures).

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.

Pull request overview

This PR tightens RFC 5987/RFC 2231 decoding in RFC2231Utility.decodeText by rejecting truncated percent-escape sequences (e.g., trailing % or %3), aligning behavior with other malformed-input handling paths and preventing silent truncation of decoded header parameter values.

Changes:

  • Update RFC2231Utility.fromHex to throw IllegalArgumentException when a % escape is truncated (fewer than two following characters).
  • Add unit tests asserting truncated percent-escapes are rejected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main/java/org/apache/commons/fileupload/RFC2231Utility.java Rejects truncated percent-encoding by throwing IllegalArgumentException instead of silently dropping the trailing escape.
src/test/java/org/apache/commons/fileupload/RFC2231UtilityTestCase.java Adds regression tests for truncated % escapes (% and %3).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@garydgregory garydgregory merged commit 51e79ab into apache:1.x Jul 13, 2026
13 of 14 checks passed
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.

3 participants