ViaVersion / ViaFabricPlus

Fabric mod to connect to EVERY Minecraft server version (Release, Beta, Alpha, Classic, Snapshots, Bedrock) with QoL fixes to the gameplay
GNU General Public License v3.0
406 stars 42 forks source link

Hypixel: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(28) + length(4) exceeds writerIndex(28): PooledUnsafeDirectByteBuf(ridx: 28, widx: 28, cap: 256) #234

Closed road2react closed 11 months ago

road2react commented 1 year ago

General Information

ViaFabricPlus, Fabric API, Custom mod (used for debugging this issue)

Bug Description

When blocks are placed very quickly, a block that would normally play a sound causes a disconnect.

image

Steps to Reproduce

  1. Join Hypixel 1.8.9
  2. Place blocks very quickly in a Bed Wars game

To debug, cancel ClientConnection.exceptionCaught and replace with a print statement. Then, placing blocks very quickly will cause many log messages to be printed.

Expected Behavior

The game should not disconnect

road2react commented 1 year ago

Likely related to https://github.com/ViaVersion/ViaLegacy/issues/33

Removing the client's block place sound shows that the server's sound packets only play on some blocks, not all of them. If blocks are placed very quickly, some block place sounds will be missing.

When placing blocks fast, it takes time (network latency) for the block to be registered on the server and sent back to the client. If a second block is placed on the first block before the block is registered on the server, the error in this issue would occur.

Back in 2.7.3, this would cause sounds to be removed, but now it disconnects in the latest version.

FlorianMichael commented 1 year ago

Hi, thanks for you report and sorry for the delayed response.

How do the errors look like without your custom mod? You can't just change the exceptionCaught() in ViaVersion because we throw exceptions internally to cancel packet handling.

I added a setting in ViaFabricPlus -> General in the meantime: "Ignore packet translation errors", try setting it to "Cancel and notify" and see what happens.

It would also be good if you try if the same issue happens with ViaProxy, so we know which project it is internally.

FlorianMichael commented 11 months ago

Closing this due inactivity, if anyone has updates to this, I'll reopen the issue

road2react commented 9 months ago

Tested on 3.0.2

If you connect to a vanilla 1.8.9 server, the client side block place sound (didn't exist in original 1.8.9) plays, while the server-sent (clientbound) sound packet fails to decode, and the error is now dropped silently. No error is noticed since the missing removal of the client side sound cancels out the missing clientbound sound packet.

Connecting to Hypixel (using the 1.8.9 setting) is different: go to Housing and place 2 blocks very quickly, with the second block on top of the first block. The second block must be placed with the crosshair on one of the sides of the newly placed first block, and must be placed in a time delay less than the server connection latency. This causes the server to send 2 sound packets; the first one is played by the client while the second packet fails to be decoded by VFP. In total, while there are only 2 blocks placed, 3 block placed sounds play.

I added some extra code that prints some logs:

[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDOUT]: createPacket 63 PooledUnsafeDirectByteBuf(ridx: 24, widx: 28, cap: 256)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDOUT]: exceptionCaught, discarding error
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(28) + length(1) exceeds writerIndex(28): PooledUnsafeDirectByteBuf(ridx: 28, widx: 28, cap: 256)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:489)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:280)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.raphimc.vialoader.netty.ViaDecoder.handler$ddn000$anothermod$channelRead(ViaDecoder.java:521)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.raphimc.vialoader.netty.ViaDecoder.channelRead(ViaDecoder.java)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at de.florianmichael.viafabricplus.protocolhack.netty.ViaFabricPlusViaDecoder.channelRead(ViaFabricPlusViaDecoder.java:42)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:336)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:308)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:336)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:280)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.proxy.ProxyHandler.channelRead(ProxyHandler.java:252)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.proxy.HttpProxyHandler$HttpClientCodecWrapper.channelRead(HttpProxyHandler.java:272)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:509)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:407)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at java.base/java.lang.Thread.run(Thread.java:1623)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]: Caused by: java.lang.IndexOutOfBoundsException: readerIndex(28) + length(1) exceeds writerIndex(28): PooledUnsafeDirectByteBuf(ridx: 28, widx: 28, cap: 256)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1442)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:730)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.buffer.AbstractByteBuf.readBoolean(AbstractByteBuf.java:739)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_2540.readBoolean(class_2540.java:1263)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_5411.method_30186(class_5411.java:92)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_2713.<init>(class_2713.java:33)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_2539$class_4532.method_22310(class_2539.java:513)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_2539$class_8698.method_52923(class_2539.java:604)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at net.minecraft.class_2543.decode(class_2543.java:35)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:519)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:458)
[00:56:22] [Netty Epoll Client IO #2/INFO]: [STDERR]:   ... 51 more

The second sound packet fails to decode (it thinks the id is 63 which is Update Recipe Book?)

The first line in the log comes from NetworkState.PacketHandler.createPacket