Repository navigation
Handle zero-length and invalid bulk reads in ByteBufInputStream - #18272
Merged
normanmaurer merged 2 commits intoNov 12, 2026
Merged
Conversation
✅ All tests passed ✅🏷️ Commit: 3c890ca Learn more about TestLens at testlens.app/docs. |
Contributor
|
Auto-port PR for 4.1: #18351 |
Contributor
|
Auto-port PR for 5.0: #18352 |
normanmaurer
added a commit
that referenced
this pull request
Nov 12, 2026
The auto-port of #18272 used lambdas and try-with-resources, which do not compile with the source level 4.1 uses by default (1.6 / 1.7 depending on the JDK). Use anonymous Executable instances and try/finally instead, like the rest of the test class.
normanmaurer
pushed a commit
that referenced
this pull request
Nov 12, 2026
…putStream (#18352) Auto-port of #18272 to 5.0 Cherry-picked commit: ec663d4 --- Motivation: `ByteBufInputStream.read(byte[], int, int)` returns `-1` for a zero-length read when the stream is exhausted. It also checks the destination range only after limiting the read to the available bytes, so an invalid range can be accepted at EOF or hidden by a short read. Modification: Validate the original destination range using the existing `ObjectUtil` and `MathUtil` helpers, then return `0` for a zero-length request before checking EOF. Add regressions for empty and consumed streams and invalid destination ranges. Result: Bulk reads follow the `InputStream` contract. This adds validation for invalid ranges that previously escaped checking, and reports negative lengths as `IndexOutOfBoundsException`. `ByteBufStreamTest` executes 14 tests. The four new parameterized cases fail on the unchanged implementation and pass with the fix. The targeted Maven build and Checkstyle checks pass on JDK 21 with Java 8 release compilation. Revapi reports no API compatibility failures against 4.2.20.Final. The legacy forbidden-API checker reports JDK 21 as unsupported, so that check remains for CI. Co-authored-by: Kayokoi <[email protected]>
normanmaurer
added a commit
that referenced
this pull request
Nov 12, 2026
…putStream (#18351) Auto-port of #18272 to 4.1 Cherry-picked commit: ec663d4 --- Motivation: `ByteBufInputStream.read(byte[], int, int)` returns `-1` for a zero-length read when the stream is exhausted. It also checks the destination range only after limiting the read to the available bytes, so an invalid range can be accepted at EOF or hidden by a short read. Modification: Validate the original destination range using the existing `ObjectUtil` and `MathUtil` helpers, then return `0` for a zero-length request before checking EOF. Add regressions for empty and consumed streams and invalid destination ranges. Result: Bulk reads follow the `InputStream` contract. This adds validation for invalid ranges that previously escaped checking, and reports negative lengths as `IndexOutOfBoundsException`. `ByteBufStreamTest` executes 14 tests. The four new parameterized cases fail on the unchanged implementation and pass with the fix. The targeted Maven build and Checkstyle checks pass on JDK 21 with Java 8 release compilation. Revapi reports no API compatibility failures against 4.2.20.Final. The legacy forbidden-API checker reports JDK 21 as unsupported, so that check remains for CI. --------- Co-authored-by: Kayokoi <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
ByteBufInputStream.read(byte[], int, int)returns-1for a zero-length read when the stream is exhausted. It also checks the destination range only after limiting the read to the available bytes, so an invalid range can be accepted at EOF or hidden by a short read.Modification:
Validate the original destination range using the existing
ObjectUtilandMathUtilhelpers, then return0for a zero-length request before checking EOF. Add regressions for empty and consumed streams and invalid destination ranges.Result:
Bulk reads follow the
InputStreamcontract. This adds validation for invalid ranges that previously escaped checking, and reports negative lengths asIndexOutOfBoundsException.ByteBufStreamTestexecutes 14 tests. The four new parameterized cases fail on the unchanged implementation and pass with the fix. The targeted Maven build and Checkstyle checks pass on JDK 21 with Java 8 release compilation.Revapi reports no API compatibility failures against 4.2.20.Final. The legacy forbidden-API checker reports JDK 21 as unsupported, so that check remains for CI.