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

LineBasedFrameDecoder#findEndOfLine method exception #8256

Closed
stateIs0 opened this issue Sep 4, 2018 · 3 comments
Closed

LineBasedFrameDecoder#findEndOfLine method exception #8256

stateIs0 opened this issue Sep 4, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@stateIs0
Copy link

stateIs0 commented Sep 4, 2018

Expected behavior

decode

Actual behavior

throw IndexOutOfBoundsException

Caused by: java.lang.IndexOutOfBoundsException: index: 2, length: -1 (expected: range(0, 512))
	at io.netty.buffer.AbstractByteBuf.checkIndex0(AbstractByteBuf.java:1360)
	at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1355)
	at io.netty.buffer.AbstractByteBuf.forEachByte(AbstractByteBuf.java:1261)
	at io.netty.handler.codec.LineBasedFrameDecoder.findEndOfLine(LineBasedFrameDecoder.java:165)
	at io.netty.handler.codec.LineBasedFrameDecoder.decode(LineBasedFrameDecoder.java:94)
	at io.netty.handler.codec.LineBasedFrameDecoder.decode(LineBasedFrameDecoder.java:78)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:512)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:450)
	... 18 more

Steps to reproduce

  1. pipeline.addLast LineBasedFrameDecoder, and maxLength == 2.
  2. Start the EchoServer
  3. Start the EchoClient
  4. throw IndexOutOfBoundsException

Minimal yet complete reproducer code (or URL to code)

EchoServer:

 p.addLast(new LineBasedFrameDecoder(2, false, false));
 p.addLast(new StringDecoder());
 p.addLast(new EchoServerHandler());

EchoClient:

  @Override
  public void channelActive(ChannelHandlerContext ctx) {
    ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{0, 1, 2}));
    ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{3, 4}));
    ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{'\n'}));
    ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{5}));
  }

Netty version

master

JVM version (e.g. java -version)

1.8.0_121-b13

OS version (e.g. uname -a)

Darwin PROMOTE 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

@stateIs0
Copy link
Author

stateIs0 commented Sep 4, 2018

This was discovered by my friend @YunaiV.

@stateIs0
Copy link
Author

stateIs0 commented Sep 4, 2018

@normanmaurer may need a counter to fix this bug.

normanmaurer added a commit that referenced this issue Sep 4, 2018
Motivation:

We need to reset the offset to 0 when we fail lazy because of a too long frame.

Modifications:

- Reset offset
- Add testcase

Result:

Fixes #8256.
@normanmaurer
Copy link
Member

@stateIs0 thanks for reporting :) Fixed in #8257.

@normanmaurer normanmaurer added this to the 4.1.30.Final milestone Sep 4, 2018
@normanmaurer normanmaurer self-assigned this Sep 4, 2018
normanmaurer added a commit that referenced this issue Sep 4, 2018
Motivation:

We need to reset the offset to 0 when we fail lazy because of a too long frame.

Modifications:

- Reset offset
- Add testcase

Result:

Fixes #8256.
cuteant pushed a commit to cuteant/SpanNetty that referenced this issue Sep 7, 2018
Motivation:

We need to reset the offset to 0 when we fail lazy because of a too long frame.

Modifications:

- Reset offset
- Add testcase

Result:

Fixes netty/netty#8256.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants