This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new dd777642d6 Update internal fork of Commons Codec to 1.16.1
dd777642d6 is described below
commit dd777642d673ca50e385324a3df478398402817d
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Apr 2 19:44:49 2024 +0100
Update internal fork of Commons Codec to 1.16.1
---
MERGE.txt | 2 +-
.../apache/tomcat/util/codec/binary/Base64.java | 44 ++++++++++++----------
.../tomcat/util/codec/binary/BaseNCodec.java | 15 +++++---
.../tomcat/util/codec/binary/StringUtils.java | 9 ++++-
.../tomcat/util/codec/binary/package-info.java | 21 +++++++++++
.../apache/tomcat/util/codec/binary/package.html | 21 -----------
webapps/docs/changelog.xml | 3 ++
7 files changed, 65 insertions(+), 50 deletions(-)
diff --git a/MERGE.txt b/MERGE.txt
index b4678e08a1..c63cb30d62 100644
--- a/MERGE.txt
+++ b/MERGE.txt
@@ -43,7 +43,7 @@ Codec
Sub-tree:
src/main/java/org/apache/commons/codec
The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
-f03cbd3ba741758ead9f59bc07e6688a739a4813 (2023-01-03)
+rel/commons-codec-1.16,.1 (2024-02-09)
Note: Only classes required for Base64 encoding/decoding. The rest are removed.
FileUpload
diff --git a/java/org/apache/tomcat/util/codec/binary/Base64.java
b/java/org/apache/tomcat/util/codec/binary/Base64.java
index 884c3190d0..a733df9937 100644
--- a/java/org/apache/tomcat/util/codec/binary/Base64.java
+++ b/java/org/apache/tomcat/util/codec/binary/Base64.java
@@ -53,7 +53,7 @@ import java.util.Objects;
public class Base64 extends BaseNCodec {
/**
- * BASE32 characters are 6 bits in length.
+ * BASE64 characters are 6 bits in length.
* They are formed by taking a block of 3 octets to form a 24-bit string,
* which is converted into 4 BASE64 characters.
*/
@@ -64,9 +64,10 @@ public class Base64 extends BaseNCodec {
/**
* This array is a lookup table that translates 6-bit positive integer
index values into their "Base64 Alphabet"
* equivalents as specified in Table 1 of RFC 2045.
- *
+ * <p>
* Thanks to "commons" project in ws.apache.org for this code.
* https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
+ * </p>
*/
private static final byte[] STANDARD_ENCODE_TABLE = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
@@ -93,12 +94,14 @@ public class Base64 extends BaseNCodec {
* This array is a lookup table that translates Unicode characters drawn
from the "Base64 Alphabet" (as specified
* in Table 1 of RFC 2045) into their 6-bit positive integer equivalents.
Characters that are not in the Base64
* alphabet but fall within the bounds of the array are translated to -1.
- *
+ * <p>
* Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63.
This means decoder seamlessly handles both
* URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to
know ahead of time what to emit).
- *
+ * </p>
+ * <p>
* Thanks to "commons" project in ws.apache.org for this code.
* https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
+ * </p>
*/
private static final byte[] STANDARD_DECODE_TABLE = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
@@ -415,9 +418,10 @@ public class Base64 extends BaseNCodec {
/**
* Validates whether decoding the final trailing character is possible in
the context
* of the set of possible base 64 values.
- *
- * <p>The character is valid if the lower bits within the provided mask
are zero. This
+ * <p>
+ * The character is valid if the lower bits within the provided mask are
zero. This
* is used to test the final trailing base-64 digit is zero in the bits
that will be discarded.
+ * </p>
*
* @param emptyBitsMask The mask of the lower bits that should be empty
* @param context the context to be used
@@ -450,7 +454,7 @@ public class Base64 extends BaseNCodec {
*/
private final byte[] encodeTable;
- // Only one decode table currently; keep for consistency with Base32 code
+ /** Only one decode table currently; keep for consistency with Base32
code. */
private final byte[] decodeTable;
/**
@@ -657,8 +661,8 @@ public class Base64 extends BaseNCodec {
context.modulus = (context.modulus+1) %
BYTES_PER_ENCODED_BLOCK;
context.ibitWorkArea = (context.ibitWorkArea <<
BITS_PER_ENCODED_BYTE) + result;
if (context.modulus == 0) {
- buffer[context.pos++] = (byte) ((context.ibitWorkArea
>> 16) & MASK_8BITS);
- buffer[context.pos++] = (byte) ((context.ibitWorkArea
>> 8) & MASK_8BITS);
+ buffer[context.pos++] = (byte) (context.ibitWorkArea
>> 16 & MASK_8BITS);
+ buffer[context.pos++] = (byte) (context.ibitWorkArea
>> 8 & MASK_8BITS);
buffer[context.pos++] = (byte) (context.ibitWorkArea &
MASK_8BITS);
}
}
@@ -679,13 +683,13 @@ public class Base64 extends BaseNCodec {
case 2 : // 12 bits = 8 + 4
validateCharacter(MASK_4BITS, context);
context.ibitWorkArea = context.ibitWorkArea >> 4; // dump
the extra 4 bits
- buffer[context.pos++] = (byte) ((context.ibitWorkArea) &
MASK_8BITS);
+ buffer[context.pos++] = (byte) (context.ibitWorkArea &
MASK_8BITS);
break;
case 3 : // 18 bits = 8 + 8 + 2
validateCharacter(MASK_2BITS, context);
context.ibitWorkArea = context.ibitWorkArea >> 2; // dump
2 bits
- buffer[context.pos++] = (byte) ((context.ibitWorkArea >>
8) & MASK_8BITS);
- buffer[context.pos++] = (byte) ((context.ibitWorkArea) &
MASK_8BITS);
+ buffer[context.pos++] = (byte) (context.ibitWorkArea >> 8
& MASK_8BITS);
+ buffer[context.pos++] = (byte) (context.ibitWorkArea &
MASK_8BITS);
break;
default:
throw new IllegalStateException(sm.getString(
@@ -734,9 +738,9 @@ public class Base64 extends BaseNCodec {
break;
case 1 : // 8 bits = 6 + 2
// top 6 bits:
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 2) & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 2 & MASK_6BITS];
// remaining 2:
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
<< 4) & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
<< 4 & MASK_6BITS];
// URL-SAFE skips the padding to further reduce size.
if (encodeTable == STANDARD_ENCODE_TABLE) {
buffer[context.pos++] = pad;
@@ -745,9 +749,9 @@ public class Base64 extends BaseNCodec {
break;
case 2 : // 16 bits = 6 + 6 + 4
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 10) & MASK_6BITS];
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 4) & MASK_6BITS];
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
<< 2) & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 10 & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 4 & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
<< 2 & MASK_6BITS];
// URL-SAFE skips the padding to further reduce size.
if (encodeTable == STANDARD_ENCODE_TABLE) {
buffer[context.pos++] = pad;
@@ -773,9 +777,9 @@ public class Base64 extends BaseNCodec {
}
context.ibitWorkArea = (context.ibitWorkArea << 8) + b; //
BITS_PER_BYTE
if (0 == context.modulus) { // 3 bytes = 24 bits = 4 * 6 bits
to extract
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 18) & MASK_6BITS];
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 12) & MASK_6BITS];
- buffer[context.pos++] = encodeTable[(context.ibitWorkArea
>> 6) & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 18 & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 12 & MASK_6BITS];
+ buffer[context.pos++] = encodeTable[context.ibitWorkArea
>> 6 & MASK_6BITS];
buffer[context.pos++] = encodeTable[context.ibitWorkArea &
MASK_6BITS];
context.currentLinePos += BYTES_PER_ENCODED_BLOCK;
if (lineLength > 0 && lineLength <=
context.currentLinePos) {
diff --git a/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
b/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
index 80ebaeb288..394f57fddc 100644
--- a/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
+++ b/java/org/apache/tomcat/util/codec/binary/BaseNCodec.java
@@ -136,7 +136,7 @@ public abstract class BaseNCodec {
/**
* The maximum size buffer to allocate.
*
- * <p>This is set to the same size used in the JDK {@code
java.util.ArrayList}:</p>
+ * <p>This is set to the same size used in the JDK {@link
java.util.ArrayList}:</p>
* <blockquote>
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
@@ -262,6 +262,7 @@ public abstract class BaseNCodec {
/**
* Note {@code lineLength} is rounded down to the nearest multiple of the
encoded block size.
* If {@code chunkSeparatorLength} is zero, then chunking is disabled.
+ *
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 =
3)
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
* @param lineLength if > 0, use chunking with a length {@code
lineLength}
@@ -275,6 +276,7 @@ public abstract class BaseNCodec {
/**
* Note {@code lineLength} is rounded down to the nearest multiple of the
encoded block size.
* If {@code chunkSeparatorLength} is zero, then chunking is disabled.
+ *
* @param unencodedBlockSize the size of an unencoded block (e.g. Base64 =
3)
* @param encodedBlockSize the size of an encoded block (e.g. Base64 = 4)
* @param lineLength if > 0, use chunking with a length {@code
lineLength}
@@ -286,7 +288,7 @@ public abstract class BaseNCodec {
this.unencodedBlockSize = unencodedBlockSize;
this.encodedBlockSize = encodedBlockSize;
final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0;
- this.lineLength = useChunking ? (lineLength / encodedBlockSize) *
encodedBlockSize : 0;
+ this.lineLength = useChunking ? lineLength / encodedBlockSize *
encodedBlockSize : 0;
this.chunkSeparatorLength = chunkSeparatorLength;
this.pad = pad;
}
@@ -448,7 +450,7 @@ public abstract class BaseNCodec {
}
/**
- * Get the default buffer size. Can be overridden.
+ * Gets the default buffer size. Can be overridden.
*
* @return the default buffer size.
*/
@@ -467,10 +469,10 @@ public abstract class BaseNCodec {
public long getEncodedLength(final byte[] pArray) {
// Calculate non-chunked size - rounded up to allow for padding
// cast to long is needed to avoid possibility of overflow
- long len = ((pArray.length + unencodedBlockSize-1) /
unencodedBlockSize) * (long) encodedBlockSize;
+ long len = (pArray.length + unencodedBlockSize-1) /
unencodedBlockSize * (long) encodedBlockSize;
if (lineLength > 0) { // We're using chunking
// Round up to nearest multiple
- len += ((len + lineLength-1) / lineLength) * chunkSeparatorLength;
+ len += (len + lineLength-1) / lineLength * chunkSeparatorLength;
}
return len;
}
@@ -532,7 +534,8 @@ public abstract class BaseNCodec {
* Extracts buffered data into the provided byte[] array, starting at
position bPos, up to a maximum of bAvail
* bytes. Returns how many bytes were actually extracted.
* <p>
- * Package protected for access from I/O streams.
+ * Package private for access from I/O streams.
+ * </p>
*
* @param b
* byte[] array to extract the buffered data into.
diff --git a/java/org/apache/tomcat/util/codec/binary/StringUtils.java
b/java/org/apache/tomcat/util/codec/binary/StringUtils.java
index 6a2b8131f6..ab050f3509 100644
--- a/java/org/apache/tomcat/util/codec/binary/StringUtils.java
+++ b/java/org/apache/tomcat/util/codec/binary/StringUtils.java
@@ -26,7 +26,8 @@ import java.nio.charset.StandardCharsets;
*
* <p>This class is immutable and thread-safe.</p>
*
- * @see <a
href="http://download.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
charsets</a>
+ * @see Charset
+ * @see StandardCharsets
* @since 1.4
*/
public class StringUtils {
@@ -55,7 +56,7 @@ public class StringUtils {
* Thrown if {@link StandardCharsets#UTF_8} is not
initialized, which should never happen
* since it is required by the Java platform specification.
* @since As of 1.7, throws {@link NullPointerException} instead of
UnsupportedEncodingException
- * @see <a
href="http://download.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard
charsets</a>
+ * @see Charset
*/
public static byte[] getBytesUtf8(final String string) {
return getBytes(string, StandardCharsets.UTF_8);
@@ -108,4 +109,8 @@ public class StringUtils {
public static String newStringUtf8(final byte[] bytes) {
return newString(bytes, StandardCharsets.UTF_8);
}
+
+ private StringUtils() {
+ // empty
+ }
}
\ No newline at end of file
diff --git a/java/org/apache/tomcat/util/codec/binary/package-info.java
b/java/org/apache/tomcat/util/codec/binary/package-info.java
new file mode 100644
index 0000000000..605aeded44
--- /dev/null
+++ b/java/org/apache/tomcat/util/codec/binary/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Base64 String encoding and decoding.
+ */
+package org.apache.tomcat.util.codec.binary;
diff --git a/java/org/apache/tomcat/util/codec/binary/package.html
b/java/org/apache/tomcat/util/codec/binary/package.html
deleted file mode 100644
index 13345ece40..0000000000
--- a/java/org/apache/tomcat/util/codec/binary/package.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<!--
-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.
--->
-<html>
- <body>
- Base64, Base32, Binary, and Hexadecimal String encoding and decoding.
- </body>
-</html>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d41174a6e1..735429b85d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -171,6 +171,9 @@
<update>
Update the internal fork of Apache Commons BCEL to 6.8.2. (markt)
</update>
+ <update>
+ Update the internal fork of Apache Commons Codec to 1.16.1. (markt)
+ </update>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]