File tree Expand file tree Collapse file tree
src/java/org/apache/commons/codec/binary Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323import org .apache .commons .codec .DecoderException ;
2424import org .apache .commons .codec .EncoderException ;
2525
26+ /**
27+ * Implements common Base-N codec functions.
28+ *
29+ * This class is not thread-safe.
30+ * Each thread should use its own instance.
31+ */
2632public abstract class BaseNCodec implements BinaryEncoder , BinaryDecoder {
2733
2834 /**
@@ -424,12 +430,13 @@ protected boolean containsAlphabetOrPad(byte[] arrayOctet) {
424430 *
425431 * @param pArray byte[] array which will later be encoded
426432 *
427- * @return amount of space needed to encoded the supplied array. Returns
428- * a long since a max-len array will require > Integer.MAX_VALUE
433+ * @return amount of space needed to encoded the supplied array.
434+ * Returns a long since a max-len array will require > Integer.MAX_VALUE
429435 */
430436 public long getEncodedLength (byte [] pArray ) {
431437 // Calculate non-chunked size - rounded up to allow for padding
432- long len = ((pArray .length + unencodedBlockSize -1 ) / unencodedBlockSize ) * encodedBlockSize ;
438+ // cast to long is needed to avoid possibility of overflow
439+ long len = ((pArray .length + unencodedBlockSize -1 ) / unencodedBlockSize ) * (long ) encodedBlockSize ;
433440 if (lineLength > 0 ) { // We're using chunking
434441 // Round up to nearest multiple
435442 len += ((len + lineLength -1 ) / lineLength ) * chunkSeparatorLength ;
You can’t perform that action at this time.
0 commit comments