Validate ByteBufferBackedInputStream.read() parameters per InputStream contract - #5691
Conversation
|
https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read-byte:A-int-int- agrees that IndexOutOfBoundsException should be thrown for negative len |
|
@copilot add calls (if needed) to Objects.requireNonNull for the input byte array param and also to Objects.checkFromIndexSize |
…Objects.requireNonNull and Objects.checkFromIndexSize Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
ByteBufferBackedInputStream.read() parameters per InputStream contract
|
Hmmmh. I guess this is good, although note that this class is not part of public API nor intended to be used from outside databind code itself. |
ByteBufferBackedInputStream.read(byte[] bytes, int off, int len)doesn't validate parameters, violating theInputStreamcontract which requires throwingNullPointerExceptionfor null arrays andIndexOutOfBoundsExceptionfor negative or out-of-bounds values.Changes
Objects.requireNonNull(bytes, "bytes")to validate the byte array is not null and throwNullPointerExceptionif it isObjects.checkFromIndexSize(off, len, bytes.length)to validate parameters and throwIndexOutOfBoundsExceptionwhen:offis negativelenis negativeoff + len > bytes.length(would exceed array bounds)Example
Current behavior with invalid parameters:
Fixed behavior:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.