CAMEL-24936: camel-netty - NettyConverter.toByteArray copies only the readable bytes of the ByteBuf - #26976
Conversation
… readable bytes of the ByteBuf buffer.array() returned the whole backing array, ignoring arrayOffset()/readerIndex()/readableBytes(); for a shared or pooled backing array that can include bytes outside this buffer's own slice, and it also handed back a reference to a buffer that may later be reused. Always copy exactly the readable region instead, consistent with the non-array branch, regardless of the underlying allocator. Backport of apache#26781 to camel-4.18.x. The upgrade-guide note stays on main only. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
gnodet-bot
left a comment
There was a problem hiding this comment.
Clean cherry-pick of #26973 to camel-4.18.x. Identical code diff (only line offsets and junit5/junit6 import differ as expected between branches). Original reviewed and approved — ByteBufUtil.getBytes() correctly replaces the buggy buffer.array() that leaked the full backing array.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
davsclaus
left a comment
There was a problem hiding this comment.
Straight cherry-pick of #26781 (only a junit5 import and the 4_23 guide hunk differ), CI green. LGTM.
Since the returned byte[] is no longer a live view of the ByteBuf, could you add the matching notes to camel-4x-upgrade-guide-4_18.adoc (4.18.4 → 4.18.5) and camel-4x-upgrade-guide-4_22.adoc (4.22.1 → 4.22.2) on main, like #26963 does for sanitizeUri?
Claude Code on behalf of davsclaus
Backport of #26781 to
camel-4.18.x.Straight port of the code change —
NettyConverter.toByteArraynow returns a copy of exactly the buffer's readable region viaByteBufUtil.getBytes(buffer)(see #26781 / CAMEL-24936 for the rationale). TheNettyConverter.javaandNettyConverterTest.javachanges are identical to the merged commit (the added test keeps this branch's JUnit 5CamelTestSupportimport); the only difference is the upgrade-guide note, which is omitted becausecamel-4x-upgrade-guide-4_23.adoclives onmainonly.mvn clean install -pl components/camel-nettyis green on this branch.Claude Code on behalf of oscerd
🤖 Generated with Claude Code