This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git


The following commit(s) were added to refs/heads/master by this push:
     new 1fe568aa RFC2231Utils decodeText - Incorrect handling of percent 
encoded text (#472)
1fe568aa is described below

commit 1fe568aa5cb19e3d91226c4520c255df4a7fdb1d
Author: Chenjp <[email protected]>
AuthorDate: Sun Jun 21 05:19:18 2026 +0800

    RFC2231Utils decodeText - Incorrect handling of percent encoded text (#472)
    
    * RFC2231Utils decodeText - Incorrect handling of percent encoded text
    
    Issue:
        utf-8''%3\u8a35 -> 5
    Expectation: illegal format.
    
    raise iae when decode '%3\u8a35'.
    
    * more work
    
    ---------
    
    Co-authored-by: chenjipeng <[email protected]>
---
 .../java/org/apache/commons/fileupload2/core/RFC2231Utils.java   | 9 +++++++--
 .../apache/commons/fileupload2/core/RFC2231UtilityTestCase.java  | 5 +++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RFC2231Utils.java
 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RFC2231Utils.java
index 3e3d13d8..e3ade681 100644
--- 
a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RFC2231Utils.java
+++ 
b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RFC2231Utils.java
@@ -137,8 +137,13 @@ final class RFC2231Utils {
                 if (i > text.length() - 2) {
                     break; // unterminated sequence
                 }
-                final var b1 = HEX_DECODE[text.charAt(i++) & MASK];
-                final var b2 = HEX_DECODE[text.charAt(i++) & MASK];
+                final var c1 = text.charAt(i++);
+                final var c2 = text.charAt(i++);
+                if (c1 >= ASCII_CODE_POINT_COUNT || c2 >= 
ASCII_CODE_POINT_COUNT) {
+                     throw new IllegalArgumentException();
+                }
+                final var b1 = HEX_DECODE[c1 & MASK];
+                final var b2 = HEX_DECODE[c2 & MASK];
                 if (b1 < 0 || b2 < 0) {
                     throw new IllegalArgumentException();
                 }
diff --git 
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/RFC2231UtilityTestCase.java
 
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/RFC2231UtilityTestCase.java
index bc431de0..d6825ae9 100644
--- 
a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/RFC2231UtilityTestCase.java
+++ 
b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/RFC2231UtilityTestCase.java
@@ -100,4 +100,9 @@ public final class RFC2231UtilityTestCase {
     void testDecodeInvalidHex() throws Exception {
         assertThrows(IllegalArgumentException.class, () -> 
RFC2231Utils.decodeText("ISO-8859-1''hello%HHworld"));
     }
+    
+    @Test
+    void testDecodeInvalidPercentEncoded() throws Exception {
+        assertThrows(IllegalArgumentException.class, () -> 
RFC2231Utils.decodeText("ISO-8859-1''hello%3\u8a35"));
+    }
 }

Reply via email to