Browse Source

Base64Converter not properly handling bytes with MSB set (not masking byte to int conversion). PR 54460

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1437268 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 12 years ago
parent
commit
f844348eff
5 changed files with 53 additions and 1 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +1
    -1
      src/main/org/apache/tools/ant/util/Base64Converter.java
  5. +44
    -0
      src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java

+ 1
- 0
CONTRIBUTORS View File

@@ -57,6 +57,7 @@ Christopher Charlier
Clark Archer
Clemens Hammacher
Clement OUDOT
Clive Brettingham-Moore
Conor MacNeill
Craeg Strong
Craig Cottingham


+ 3
- 0
WHATSNEW View File

@@ -72,6 +72,9 @@ Fixed bugs:
* Depend task does not handle invokeDynamic constant pool entries - java.lang.ClassFormatError: Invalid Constant Pool entry Type 18
Bugzilla Report 54090

* Base64Converter not properly handling bytes with MSB set (not masking byte to int conversion)
Bugzilla Report 54460

Other changes:
--------------



+ 4
- 0
contributors.xml View File

@@ -250,6 +250,10 @@
<first>Clement</first>
<last>OUDOT</last>
</name>
<name>
<first>Clive</first>
<last>Brettingham-Moore</last>
</name>
<name>
<first>Conor</first>
<last>MacNeill</last>


+ 1
- 1
src/main/org/apache/tools/ant/util/Base64Converter.java View File

@@ -83,7 +83,7 @@ public class Base64Converter {
// store the octets
bits24 = (octetString[i++] & BYTE_MASK) << WORD;
bits24 |= (octetString[i++] & BYTE_MASK) << BYTE;
bits24 |= octetString[i++];
bits24 |= octetString[i++] & BYTE_MASK;

bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT;
out[outIndex++] = ALPHABET[bits6];


+ 44
- 0
src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java View File

@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.util;

import junit.framework.TestCase;

import java.util.Calendar;
import java.util.TimeZone;

/**
* TestCase for Base64Converter.
*
*/
public class Base64ConverterTest extends TestCase {
public Base64ConverterTest(String s) {
super(s);
}
public void testOneValue() {
byte[] mybytes = {0, 0, (byte)0xFF};
Base64Converter base64Converter = new Base64Converter();
assertEquals("AAD/",base64Converter.encode(mybytes));
}

public void testHelloWorld() {
byte[] mybytes = "Hello World".getBytes();
Base64Converter base64Converter = new Base64Converter();
assertEquals("SGVsbG8gV29ybGQ=", base64Converter.encode(mybytes));
}
}

Loading…
Cancel
Save