Treasure2!

Treasure2!

6M Downloads

šŸž Bug Report: KeyItem.getShareTag throws NPE / ArrayIndexOutOfBoundsException

xparadise95 opened this issue Ā· 0 comments

commented
Component Version
Minecraft 1.20.1
Forge 47.3.0
TreasureĀ² 1.20.1ā€‘3.11.1
ModernFix Default (mixin.perf.nbt_memory_usage = true)
Lithium 0.11.2
PacketFixer 1.1.0
OS Debian Linux (dedicated server)

Image

Image

https://mclo.gs/o0Q0EzF

When the server attempts to sync a TreasureĀ² KeyItem (for example by opening an inventory or Refined Storage grid containing one), it crashes with either an ArrayIndexOutOfBoundsException or a NullPointerException originating in KeyItem.getShareTag(...). This disconnects all players holding that key.

Reproduction Steps
Start a Forge 1.20.1 server with TreasureĀ² v3.11.1 (plus ModernFix, Lithium, PacketFixer).

Acquire or generate a TreasureĀ² Key (the corruption appears after an update).

Put that key into a playerā€™s inventory or place it inside a Refined Storage network.

Open the player inventory or open the Refined Storage GUI.

ā†’ The server immediately prints a stack trace and forcibly disconnects the playe

ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 3
at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap.rehash(Object2ObjectOpenHashMap.java:1270)
at net.minecraft.nbt.CompoundTag.merge(CompoundTag.java:172)
at mod.gottsch.forge.treasure2.core.item.KeyItem.getShareTag(KeyItem.java:170)
ā€¦ (packet encoding) ā€¦

NullPointerException:
java.lang.NullPointerException: Cannot invoke ā€œnet.minecraft.nbt.CompoundTag.getString(String)ā€ because ā€œtagā€ is null
at mod.gottsch.forge.treasure2.core.item.KeyItem.getShareTag(KeyItem.java:170)
ā€¦ (packet encoding) ā€¦

Both errors originate from KeyItem.getShareTag(...) producing invalid or null NBT data. That invalid tag is then serialized by Minecraftā€™s packet encoder, causing the server crash.

Suggested Fix:
In KeyItem.getShareTag():
Check for itemStack.getTag() == null before merging.
Create a new empty CompoundTag if needed.
Avoid using FastUtil rehash without validating index bounds.

Thank you