mrglavas 2004/10/06 13:08:28
Modified: java/src/org/apache/xerces/impl/dv/util HexBin.java
Log:
Fixing an AIOOBE. When validating content declared
to be hexBinary we were throwing the exception if
the value contained characters U+255 and above.
Revision Changes Path
1.12 +14 -9 xml-xerces/java/src/org/apache/xerces/impl/dv/util/HexBin.java
Index: HexBin.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/util/HexBin.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HexBin.java 6 Oct 2004 14:56:52 -0000 1.11
+++ HexBin.java 6 Oct 2004 20:08:28 -0000 1.12
@@ -47,17 +47,19 @@
hexNumberTable[i] = (byte) ( i-'a' + 10 );
}
- for(int i = 0; i<10; i++ )
+ for(int i = 0; i<10; i++ ) {
lookUpHexAlphabet[i] = (char)('0'+i);
- for(int i = 10; i<=15; i++ )
+ }
+ for(int i = 10; i<=15; i++ ) {
lookUpHexAlphabet[i] = (char)('A'+i -10);
+ }
}
/**
* Encode a byte array to hex string
*
- * @param binaryData array of byte to encode
- * @return return encoded string
+ * @param binaryData array of byte to encode
+ * @return return encoded string
*/
static public String encode(byte[] binaryData) {
if (binaryData == null)
@@ -79,8 +81,8 @@
/**
* Decode hex string to a byte array
*
- * @param encoded encoded string
- * @return return array of byte to encode
+ * @param encoded encoded string
+ * @return return array of byte to encode
*/
static public byte[] decode(String encoded) {
if (encoded == null)
@@ -93,11 +95,14 @@
int lengthDecode = lengthData / 2;
byte[] decodedData = new byte[lengthDecode];
byte temp1, temp2;
+ char tempChar;
for( int i = 0; i<lengthDecode; i++ ){
- temp1 = hexNumberTable[binaryData[i*2]];
+ tempChar = binaryData[i*2];
+ temp1 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
if (temp1 == -1)
return null;
- temp2 = hexNumberTable[binaryData[i*2+1]];
+ tempChar = binaryData[i*2+1];
+ temp2 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
if (temp2 == -1)
return null;
decodedData[i] = (byte)((temp1 << 4) | temp2);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]