mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
Fix ArrayIndexOutOfBounds when writing big buffer
If ChannelOutputStream.write(byte[], int, int) was called with a buffer larger than bufferSize the loop in that method would call DataBuffer.write with a small len and a large off. This would cause the calculation in line 90 to return a negative n leading to a ArrayIndexOutOfBounds. The offset should not be taken into account when calculating the number of bytes to put in the buffer.
This commit is contained in:
@@ -87,7 +87,7 @@ public final class ChannelOutputStream
|
|||||||
flush(bufferSize);
|
flush(bufferSize);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
final int n = Math.min(len - off, win.getMaxPacketSize() - bufferSize);
|
final int n = Math.min(len, win.getMaxPacketSize() - bufferSize);
|
||||||
packet.putRawBytes(data, off, n);
|
packet.putRawBytes(data, off, n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -214,4 +214,4 @@ public final class ChannelOutputStream
|
|||||||
return "< ChannelOutputStream for Channel #" + chan.getID() + " >";
|
return "< ChannelOutputStream for Channel #" + chan.getID() + " >";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user