Skip to content

Commit

Permalink
Make the length check overflow safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Dec 28, 2019
1 parent e4de423 commit 95bc7e1
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -1030,8 +1030,9 @@ public final void add(final byte[] data, final int offset, final int length) {
// main block
// remaining

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

0 comments on commit 95bc7e1

Please sign in to comment.