Skip to content

Commit 95bc7e1

Browse files
committed
Make the length check overflow safe.
1 parent e4de423 commit 95bc7e1

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/main/java/org/apache/commons/codec/digest/MurmurHash3.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,9 @@ public final void add(final byte[] data, final int offset, final int length) {
10301030
// main block
10311031
// remaining
10321032

1033-
// Check if the unprocessed bytes and new bytes can fill a block of 4
1034-
if (unprocessedLength + length < BLOCK_SIZE) {
1033+
// Check if the unprocessed bytes and new bytes can fill a block of 4.
1034+
// Make this overflow safe in the event that length is Integer.MAX_VALUE.
1035+
if (unprocessedLength + length - BLOCK_SIZE < 0) {
10351036
// Not enough so add to the unprocessed bytes
10361037
System.arraycopy(data, offset, unprocessed, unprocessedLength, length);
10371038
unprocessedLength += length;

0 commit comments

Comments
 (0)