Author: fanningpj
Date: Tue Jun  2 10:53:00 2026
New Revision: 1934874

Log:
[XMLBEANS-665] fix out-of-bounds read in HexBin for byte 0xff. Thanks to 
aizu-m. This closes #33

Modified:
   xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java
   xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java      
Tue Jun  2 10:50:20 2026        (r1934873)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/HexBin.java      
Tue Jun  2 10:53:00 2026        (r1934874)
@@ -25,7 +25,7 @@ import java.nio.charset.StandardCharsets
  * </p>
  */
 public final class HexBin {
-    static private final int BASELENGTH = 255;
+    static private final int BASELENGTH = 256;
     static private final int LOOKUPLENGTH = 16;
     static private final byte[] hexNumberTable = new byte[BASELENGTH];
     static private final byte[] lookUpHexAlphabet = new byte[LOOKUPLENGTH];

Modified: xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java
==============================================================================
--- xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java   Tue Jun  2 
10:50:20 2026        (r1934873)
+++ xmlbeans/trunk/src/test/java/misc/checkin/HexBinTest.java   Tue Jun  2 
10:53:00 2026        (r1934874)
@@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets
 import java.util.Locale;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
 public class HexBinTest {
 
@@ -37,6 +38,15 @@ public class HexBinTest {
     }
 
     @Test
+    void testInvalidHighByte() {
+        // 0xFF is not a hex digit; decode must report it like any other 
invalid
+        // input (null) instead of indexing past the lookup table.
+        assertNull(HexBin.decode(new byte[]{(byte) 0xFF, (byte) 0xFF}));
+        assertNull(HexBin.decode(new String(new byte[]{(byte) 0xFF, (byte) 
0xFF},
+                StandardCharsets.ISO_8859_1)));
+    }
+
+    @Test
     void knownValue() throws XPathException {
         // I've looked for comparison values but the following definition 
seems to be wrong,
         // because Saxon also returns the same encoded value


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to