Browse Source

Attempt to fix broken encoding due to miscalculated output buffer.

PR: 34734


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278228 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
0c8407b311
1 changed files with 31 additions and 38 deletions
  1. +31
    -38
      src/main/org/apache/tools/ant/taskdefs/Get.java

+ 31
- 38
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -343,31 +343,27 @@ public class Get extends Task {
*
*********************************************************************/

protected static class Base64Converter {

public final char [ ] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63


public String encode(String s) {
return encode (s.getBytes());
protected static class Base64Converter {

public final char[] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/'}; // 56 to 63

public String encode(String s) {
return encode(s.getBytes());
}

public String encode(byte[ ] octetString) {
int bits24;
int bits6;

char [ ] out
= new char[((octetString.length - 1) / 3 + 1) * 4];
public String encode(byte[] octetString) {
int bits24;
int bits6;

int outIndex = 0;
StringBuffer buf = new StringBuffer();
int i = 0;

while ((i + 3) <= octetString.length) {
@@ -376,44 +372,41 @@ public class Get extends Task {
bits24 |= (octetString[i++] & 0xFF) << 8;

bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x0000003F);
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
}

if (octetString.length - i == 2) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits24 |= (octetString[i + 1] & 0xFF) << 8;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);

// padding
out[outIndex++] = '=';
buf.append('=');
} else if (octetString.length - i == 1) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
buf.append(alphabet[bits6]);
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[ bits6 ];
buf.append(alphabet[bits6]);

// padding
out[outIndex++] = '=';
out[outIndex++] = '=';
buf.append("==");
}

return new String(out);
return buf.toString();
}
}
}

public interface DownloadProgress {
/**


Loading…
Cancel
Save