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

Sending garbage data will raise weird exception #100

Closed
ph opened this issue Jul 19, 2016 · 1 comment
Closed

Sending garbage data will raise weird exception #100

ph opened this issue Jul 19, 2016 · 1 comment

Comments

@ph
Copy link
Contributor

ph commented Jul 19, 2016

If you throw garbage at a plain text beats input, you get all kinds of fun exceptions:

To reproduce:

% bin/logstash --log.level debug -e 'input { beats { port => 12345 } }'
...
% dd if=/dev/urandom bs=4k count=1 | nc localhost 12345

full output

Jul 11, 2016 3:05:14 PM io.netty.channel.AbstractChannelHandlerContext invokeExceptionCaught
WARNING: An exception was thrown by a user handler's exceptionCaught() method while handling the following exception:
io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Illegal initial capacity: -1982301064
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:36)
        at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:339)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393)
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Illegal initial capacity: -1982301064
        at java.util.HashMap.<init>(HashMap.java:448)
        at java.util.HashMap.<init>(HashMap.java:467)
        at org.logstash.beats.BeatsParser.decode(BeatsParser.java:125)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411)
        ... 9 more
@ph
Copy link
Contributor Author

ph commented Jul 20, 2016

The beats parser get confused by the frame it received and just crash, So the way to fix this is to make sure we have received a valid header at the beginning of the batch to continue with the parser if its not the case we can just raise and InvalidFrameException or UnknownProtocol Error.

ph added a commit to ph/logstash-input-beats that referenced this issue Jul 20, 2016
This change make sure the state machien correctly recover from sending
garbage data over the write. The current strategy is to check to make
sure the frametype are correctly send if we received an unknown frame
type we will assume that the frame is poisonous, we will raise a custom
exception `InvalidFrameProtocol` with the associated bytes and will
terminate the connection since we cannot do anything with it.

Fixes: logstash-plugins#100
ph added a commit to ph/logstash-input-beats that referenced this issue Jul 25, 2016
This change make sure the state machien correctly recover from sending
garbage data over the write. The current strategy is to check to make
sure the frametype are correctly send if we received an unknown frame
type we will assume that the frame is poisonous, we will raise a custom
exception `InvalidFrameProtocol` with the associated bytes and will
terminate the connection since we cannot do anything with it.

Fixes: logstash-plugins#100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant