packetevents icon indicating copy to clipboard operation
packetevents copied to clipboard

IndexOutOfBoundsException in PacketEvents while using Matrix

Open v4r1n opened this issue 1 year ago • 6 comments

Describe the bug When executing the /ecoenchants gui command and I select the special enchantment book, I get kicked off the server when clicking the special enchantment book. Matrix throws an IndexOutOfBoundsException related to packet handling, which seems to occur when handling the window event when clicking the enchantment book, causing the Netty buffer to crash during the processing of the item data.

Software brand Paper version 1.21.1-120-master@57c75a4

Velocity Version Velocity 3.3.0-SNAPSHOT (git-2016d148-b436)

Plugins Spark profile#1: https://spark.lucko.me/bDBUBmexU8 #1 packetevents (v2.5.0) Spark profile#2: https://spark.lucko.me/cur98ZyVSd #2 packetevents (v2.5.1+e13632774-SNAPSHOT)

How To Reproduce Steps to reproduce the behavior:

  1. Install the Matrix plugin alongside EcoEnchants.
  2. Execute the /ecoenchants gui command.
  3. When selecting the special enchantment book in the GUI window,
  4. Observe the server logs for the IndexOutOfBoundsException error.

Expected behavior The plugin should open /ecoenchants gui and use the special enchantment book without crashing or throwing any exceptions, allowing the game to run smoothly.

Actual Behavior The server throws IndexOutOfBoundsException and logs an error stack trace when trying to read from the packet buffer, resulting in the inability to use the special enchantment book in the EcoEnchants GUI window properly.

Screenshots https://github.com/user-attachments/assets/fcc23773-7901-4c25-adfd-f351e51d3674

Additional context It seems to be a problem when Matrix interacts with packets related to the interaction of items in EcoEnchants custom configuration integration. I have tested with Matrix developer, he helped me fully with the Matrix protection plugin. He said that this has a problem with packetevents-spigot-2.5.0 & packetevents-velocity-2.5.0, you guys who developed packetevents need to help fix this.

v4r1n avatar Oct 19 '24 07:10 v4r1n

When I bounce out of this issue, I get a notification in the chat box like this:

image

v4r1n avatar Oct 19 '24 07:10 v4r1n

report the bug to packetevents Matrix is using packetevents 2.5.1 snapshot bug error: https://paste.helpch.at/ledoyeveyi.css

v4r1n avatar Oct 19 '24 07:10 v4r1n

I can't reproduce this issue using the latest packetevents build and latest ecoenchants version I can't test this using Matrix, as Matrix is not available for free and also closed-source

https://github.com/user-attachments/assets/f57105d0-445c-4c53-9b4e-4267c2e47b8d

Are you running the latest Matrix version and does Matrix use the latest packetevents build?

booky10 avatar Oct 21 '24 15:10 booky10

Dev Matrix: image I'm use image and PacketEvent image

v4r1n avatar Oct 23 '24 21:10 v4r1n

I'm the author of Matrix and I'm using implementation("com.github.retrooper:packetevents-spigot:2.5.1-SNAPSHOT")

Here's the stacktrace of error:

[13:26:47] [Netty Server IO #1/WARN]: [me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.PacketEventsAPI] PacketEvents caught an unhandled exception while calling your listener.
java.lang.IndexOutOfBoundsException: readerIndex(18) + length(1) exceeds writerIndex(18): PooledUnsafeDirectByteBuf(ridx: 18, widx: 18, cap: 18)
	at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1442) ~[netty-buffer-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:730) ~[netty-buffer-4.1.97.Final.jar:4.1.97.Final]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.io.github.retrooper.packetevents.netty.buffer.ByteBufOperatorModernImpl.readByte(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.netty.buffer.ByteBufHelper.readByte(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readByte(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readVarInt(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readMappedEntity(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readMappedEntity(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments.lambda$read$0(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readMap(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments.read(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.protocol.component.StaticComponentType.read(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readItemStackModern(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readItemStack(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow.read(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.readEvent(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.<init>(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.PacketWrapper.<init>(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow.<init>(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix._.qa.u(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix._.wk.onPacketReceive(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.event.PacketReceiveEvent.call(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.event.EventManager.callEvent(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.com.github.retrooper.packetevents.util.PacketEventsImplHelper.handleServerBoundPacket(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.io.github.retrooper.packetevents.injector.handlers.PacketEventsDecoder.read(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.io.github.retrooper.packetevents.injector.handlers.PacketEventsDecoder.decode(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at Matrix_7.11.5.jar/me.rerere.matrix.thirdparty.io.github.retrooper.packetevents.injector.handlers.PacketEventsDecoder.decode(Unknown Source) ~[Matrix_7.11.5.jar:?]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at ProtocolLib.jar/com.comphenix.protocol.injector.netty.channel.InboundProtocolReader.channelRead(InboundProtocolReader.java:25) ~[ProtocolLib.jar:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.flow.FlowControlHandler.dequeue(FlowControlHandler.java:202) ~[netty-handler-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.flow.FlowControlHandler.channelRead(FlowControlHandler.java:164) ~[netty-handler-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) ~[netty-handler-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.handler.flush.FlushConsolidationHandler.channelRead(FlushConsolidationHandler.java:152) ~[netty-handler-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar:4.1.97.Final]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
[13:26:47] [Server thread/INFO]: z1ncq lost connection: Internal Exception: io.netty.handler.codec.DecoderException: Failed to decode packet 'serverbound/minecraft:container_click'

image

re-ovo avatar Oct 24 '24 00:10 re-ovo

also experiencing this error with custom model data jukebox discs

mitchellonii avatar Nov 11 '24 09:11 mitchellonii