isBase64 throws ArrayIndexOutOfBoundsException on some non-BASE64 bytes
-----------------------------------------------------------------------
Key: CODEC-68
URL: https://issues.apache.org/jira/browse/CODEC-68
Project: Commons Codec
Issue Type: Bug
Affects Versions: 1.3
Reporter: Robert Rodewald
the following code throws an ArrayIndexOutOfBoundsException although it is
perfectly valid (the byte 0x9c should be ignored according to the standard):
byte[x] = new byte[] { 'n', 'A', '=', '=', 0x9c };
Base64.decodeBase64(x);
The problem is the following method:
private static boolean isBase64(byte octect) {
if (octect == PAD) {
return true;
} else if (base64Alphabet[octect] == -1) {
return false;
} else {
return true;
}
}
in Java octect is a *signed* value, so it is not correct to use it as an offset
for an array [0..254] which base64Alphabet is. 0x9c is -100!
FIX:
use base64Alphabet[ 0xff & octect ] in the "else if" block to convert the octet
prior using it as an offset for the lookup table
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.