Skip to content

Commit

Permalink
[Java] Deal with integer overflow in resulting offset check on Mutabl…
Browse files Browse the repository at this point in the history
…eDirectBufferOutputStream.
  • Loading branch information
mjpt777 committed Mar 13, 2016
1 parent 868a3a1 commit c797809
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void write(final int b) throws IOException
{
if (position == length)
{
throw new IllegalStateException("insufficient capacity in the buffer");
throw new IllegalStateException("position has reached the end of underlying buffer");
}

buffer.putByte(offset + position, (byte)b);
Expand All @@ -129,7 +129,8 @@ public void write(final int b) throws IOException
*/
public void write(final byte[] srcBytes, final int srcOffset, final int length) throws IOException
{
if (position + length >= this.length)
final long resultingOffset = position + ((long)length);
if (resultingOffset >= this.length)
{
throw new IllegalStateException("insufficient capacity in the buffer");
}
Expand Down

0 comments on commit c797809

Please sign in to comment.