Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NettyDataBuffer#toByteBuffer fails if readPosition > 0 #31605

Closed
chringwer opened this issue Nov 14, 2023 · 1 comment
Closed

NettyDataBuffer#toByteBuffer fails if readPosition > 0 #31605

chringwer opened this issue Nov 14, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@chringwer
Copy link

NettyDataBuffer uses this.byteBuf.nioBuffer() internally which will allocates fewer bytes if readPosition is greater than 0. The following checks are then failing with an IndexOutOfBoundsException.

dest.put(destPos, this.byteBuf.nioBuffer(), srcPos, length);

Here is a simple repro case (which passes for DefaultDataBufferFactory):

@Test
void shouldHonorSourceBuffersReadPosition() {
  DataBufferFactory bufferFactory = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT);

  DataBuffer sourceBuffer = bufferFactory.wrap("Hello World".getBytes(UTF_8));

  sourceBuffer.readPosition("Hello ".getBytes(UTF_8).length);
  ByteBuffer targetBuffer = ByteBuffer.allocate(sourceBuffer.readableByteCount());

  sourceBuffer.toByteBuffer(targetBuffer);

  assertThat(new String(targetBuffer.array(), UTF_8)).isEqualTo("World");
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 14, 2023
@poutsma poutsma self-assigned this Nov 14, 2023
@poutsma poutsma added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 15, 2023
@poutsma poutsma added this to the 6.0.14 milestone Nov 15, 2023
@poutsma
Copy link
Contributor

poutsma commented Nov 15, 2023

Thanks for spotting this, fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants