Validate read() parameters in InputStream and Reader implementations#1544
Validate read() parameters in InputStream and Reader implementations#1544
Conversation
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
There was a problem hiding this comment.
@copilot revert the use of Objects.checkFromIndexSize here and add back the old check that called reportBounds - keep the new test
There was a problem hiding this comment.
Done in e6bb0f6. Reverted to use reportBounds for bounds checking while keeping Objects.requireNonNull for null validation. The test continues to work since ArrayIndexOutOfBoundsException is a subclass of IndexOutOfBoundsException.
… UTF32Reader Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. 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:
|
|
@copilot fix the test issue |
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Fixed in c21d33d. Moved the parameter validation (using reportBounds) before the early returns for EOF and zero-length checks. This ensures negative length values are caught and throw ArrayIndexOutOfBoundsException as expected by the test. 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:
|
|
@copilot don't try to fix this yet but can you advise on this Android animal-sniffer issue that this PR introduces? |
The issue is that Options to fix:
I'd recommend option 1 for consistency with UTF32Reader (which uses reportBounds with similar logic). The jackson-databind PR likely has the same issue and may need the same fix. |
…droid compatibility Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
to match jackson-databind
Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Done in 60e8ead. Rebased onto 3.x (picking up Android SDK 34 update) and reverted the manual bounds checking back to 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:
|
Adds parameter validation to
MergedStreamandUTF32Readerper InputStream/Reader contract, matching jackson-databind#5691 approach.Changes
MergedStream.java
Objects.requireNonNull()Objects.checkFromIndexSize()(Java 9 API, compatible with Android SDK 34)UTF32Reader.java
Objects.requireNonNull()reportBounds()validation before early returns to catch negative lengthsreportBounds()Tests
MergedStreamTest.parameterValidation()andUTF32ReaderTest.parameterValidation()Example
Uses
Objects.checkFromIndexSize()since Android SDK baseline was updated to 34 (supports Java 9+ APIs).💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.