You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/01/27 21:23:11 UTC
svn commit: r1064292 -
/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java
Author: sebb
Date: Thu Jan 27 20:23:10 2011
New Revision: 1064292
URL: http://svn.apache.org/viewvc?rev=1064292&view=rev
Log:
FindBugs detected potential calculation overflow
Modified:
commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java?rev=1064292&r1=1064291&r2=1064292&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java (original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/binary/BaseNCodec.java Thu Jan 27 20:23:10 2011
@@ -23,6 +23,12 @@ import org.apache.commons.codec.BinaryEn
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
+/**
+ * Implements common Base-N codec functions.
+ *
+ * This class is not thread-safe.
+ * Each thread should use its own instance.
+ */
public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
/**
@@ -424,12 +430,13 @@ public abstract class BaseNCodec impleme
*
* @param pArray byte[] array which will later be encoded
*
- * @return amount of space needed to encoded the supplied array. Returns
- * a long since a max-len array will require > Integer.MAX_VALUE
+ * @return amount of space needed to encoded the supplied array.
+ * Returns a long since a max-len array will require > Integer.MAX_VALUE
*/
public long getEncodedLength(byte[] pArray) {
// Calculate non-chunked size - rounded up to allow for padding
- long len = ((pArray.length + unencodedBlockSize-1) / unencodedBlockSize) * encodedBlockSize;
+ // cast to long is needed to avoid possibility of overflow
+ 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;