Skip to content

Add missing bounds check to AdaptiveByteBuf.getBytes(...) channel variants - #17620

Merged
normanmaurer merged 1 commit into
netty:4.2from
laosijikaichele:4.2-checkindex
Sep 25, 2026
Merged

normanmaurer merged 1 commit into
netty:4.2from
laosijikaichele:4.2-checkindex

Conversation

@laosijikaichele

Copy link
Copy Markdown
Contributor

Motivation:

AdaptiveByteBuf.getBytes(int, GatheringByteChannel, int) and AdaptiveByteBuf.getBytes(int, FileChannel, long, int) do not call checkIndex(index, length), unlike other ByteBuf implementations.

These methods write from the cached tmpNioBuf, whose limit is maxFastCapacity (the size of the underlying segment) rather than capacity(). An out-of-bounds request that still fits within the segment is therefore not rejected: instead of throwing IndexOutOfBoundsException, the buffer silently writes bytes located beyond its own capacity to the channel.

Modification:

Add the missing checkIndex(index, length) to both methods, and add tests covering both channel variants.

Result:

AdaptiveByteBuf no longer reads past its capacity, and throws IndexOutOfBoundsException like the other ByteBuf implementations.

@testlens-app

testlens-app Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Failed Jobs without Test Failures

❌ Build PR / linux-x86_64-java11 build

Test Summary

Build PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) ❌ 4% 🟡

🏷️ Commit: 5a3113d
▶️ Tests: 464836 executed
🟡 Checks: 29/32 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:368)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:194)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:172)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:158)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:155)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:155)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Rerun Controls

Note

Checks are currently running using the configuration below.

Select tests to mute in this pull request:

🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo)

Reuse successful test results:

🔲 ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

🔲 Rerun jobs


Learn more about TestLens at testlens.app/docs.

}

@Test
public void getBytesBoundaryCheckWithFileChannel() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laosijikaichele should we move the tests to AbstractByteBufAllocatorTest so we also test the others ?

@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 25, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Sep 25, 2026
@normanmaurer
normanmaurer merged commit a0c8ddc into netty:4.2 Sep 25, 2026
28 of 30 checks passed
@normanmaurer

Copy link
Copy Markdown
Member

@laosijikaichele thanks!

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17629

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Sep 25, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17630

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Sep 25, 2026
normanmaurer pushed a commit that referenced this pull request Sep 26, 2026
…...)` channel variants (#17630)

Auto-port of #17620 to 5.0
Cherry-picked commit: a0c8ddc

---
Motivation:

`AdaptiveByteBuf.getBytes(int, GatheringByteChannel, int)` and
`AdaptiveByteBuf.getBytes(int, FileChannel, long, int)` do not call
`checkIndex(index, length)`, unlike other `ByteBuf` implementations.

These methods write from the cached `tmpNioBuf`, whose limit is
`maxFastCapacity` (the size of the underlying segment) rather than
`capacity()`. An out-of-bounds request that still fits within the
segment is therefore not rejected: instead of throwing
`IndexOutOfBoundsException`, the buffer silently writes bytes located
beyond its own capacity to the channel.

Modification:

Add the missing `checkIndex(index, length)` to both methods, and add
tests covering both channel variants.

Result:

`AdaptiveByteBuf` no longer reads past its capacity, and throws
`IndexOutOfBoundsException` like the other `ByteBuf` implementations.

Co-authored-by: old driver <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 28, 2026
…...)` channel variants (#17629)

Auto-port of #17620 to 4.1
Cherry-picked commit: a0c8ddc

---
Motivation:

`AdaptiveByteBuf.getBytes(int, GatheringByteChannel, int)` and
`AdaptiveByteBuf.getBytes(int, FileChannel, long, int)` do not call
`checkIndex(index, length)`, unlike other `ByteBuf` implementations.

These methods write from the cached `tmpNioBuf`, whose limit is
`maxFastCapacity` (the size of the underlying segment) rather than
`capacity()`. An out-of-bounds request that still fits within the
segment is therefore not rejected: instead of throwing
`IndexOutOfBoundsException`, the buffer silently writes bytes located
beyond its own capacity to the channel.

Modification:

Add the missing `checkIndex(index, length)` to both methods, and add
tests covering both channel variants.

Result:

`AdaptiveByteBuf` no longer reads past its capacity, and throws
`IndexOutOfBoundsException` like the other `ByteBuf` implementations.

---------

Co-authored-by: old driver <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…...)` channel variants (netty#17629)

Auto-port of netty#17620 to 4.1
Cherry-picked commit: a0c8ddc

---
Motivation:

`AdaptiveByteBuf.getBytes(int, GatheringByteChannel, int)` and
`AdaptiveByteBuf.getBytes(int, FileChannel, long, int)` do not call
`checkIndex(index, length)`, unlike other `ByteBuf` implementations.

These methods write from the cached `tmpNioBuf`, whose limit is
`maxFastCapacity` (the size of the underlying segment) rather than
`capacity()`. An out-of-bounds request that still fits within the
segment is therefore not rejected: instead of throwing
`IndexOutOfBoundsException`, the buffer silently writes bytes located
beyond its own capacity to the channel.

Modification:

Add the missing `checkIndex(index, length)` to both methods, and add
tests covering both channel variants.

Result:

`AdaptiveByteBuf` no longer reads past its capacity, and throws
`IndexOutOfBoundsException` like the other `ByteBuf` implementations.

---------

Co-authored-by: old driver <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants