You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by bu...@apache.org on 2003/07/15 08:54:18 UTC
DO NOT REPLY [Bug 21601] New: -
Base64 may not be portable between VMs
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21601>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21601
Base64 may not be portable between VMs
Summary: Base64 may not be portable between VMs
Product: Commons
Version: 2.0 Beta 2
Platform: All
OS/Version: All
Status: NEW
Severity: Normal
Priority: Other
Component: HttpClient
AssignedTo: commons-httpclient-dev@jakarta.apache.org
ReportedBy: ortwin.glueck@nose.ch
The utils.Base64 class defines it's alphabet like so:
static {
for (int i = 0; i < BASELENGTH; i++) {
BASE64_ALPHABET[i] = -1;
}
for (int i = 'Z'; i >= 'A'; i--) {
BASE64_ALPHABET[i] = (byte) (i - 'A');
}
for (int i = 'z'; i >= 'a'; i--) {
BASE64_ALPHABET[i] = (byte) (i - 'a' + 26);
}
for (int i = '9'; i >= '0'; i--) {
BASE64_ALPHABET[i] = (byte) (i - '0' + 52);
}
BASE64_ALPHABET['+'] = 62;
BASE64_ALPHABET['/'] = 63;
for (int i = 0; i <= 25; i++) {
LOOKUP_BASE64_ALPHABET[i] = (byte) ('A' + i);
}
for (int i = 26, j = 0; i <= 51; i++, j++) {
LOOKUP_BASE64_ALPHABET[i] = (byte) ('a' + j);
}
for (int i = 52, j = 0; i <= 61; i++, j++) {
LOOKUP_BASE64_ALPHABET[i] = (byte) ('0' + j);
}
LOOKUP_BASE64_ALPHABET[62] = (byte) '+';
LOOKUP_BASE64_ALPHABET[63] = (byte) '/';
}
These casts from char to integer types make heavy use of the assumption that
characters are stored in a ASCII compatible encoding. This is however not
required by the Java Language Specs:
(byte) 'A' is not necessarily equal to 65
So this code will produce wrong results on a (hypothetical) VM that uses an
ASCII incompatible encoding to store characters. This may be a completely
virtual problem, as I do not know of any ASCII incompatible encoding of the
Unicode character set in 16-bit integers currently. Is it worth fixing this?