diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c209a5810..e6ab0018c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -57,6 +57,7 @@ Christopher Charlier Clark Archer Clemens Hammacher Clement OUDOT +Clive Brettingham-Moore Conor MacNeill Craeg Strong Craig Cottingham diff --git a/WHATSNEW b/WHATSNEW index c70be1c1d..ee5fb45dc 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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: -------------- diff --git a/contributors.xml b/contributors.xml index f726989c6..91cf53265 100644 --- a/contributors.xml +++ b/contributors.xml @@ -250,6 +250,10 @@ Clement OUDOT + + Clive + Brettingham-Moore + Conor MacNeill diff --git a/src/main/org/apache/tools/ant/util/Base64Converter.java b/src/main/org/apache/tools/ant/util/Base64Converter.java index a5f7e5b80..5d60a145f 100644 --- a/src/main/org/apache/tools/ant/util/Base64Converter.java +++ b/src/main/org/apache/tools/ant/util/Base64Converter.java @@ -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]; diff --git a/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java b/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java new file mode 100644 index 000000000..b12d7e266 --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java @@ -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)); + } +}