The data buffer created by ClientboundLevelChunkPacketData
contains an extra byte for each LevelChunkSection
using a SingleValuePalette
in the column.
This is caused by the incorrect getSerializedSize()
calculation in the Data
class of PalettedContainer
:
public int getSerializedSize() {
return 1 + this.palette.getSerializedSize() + FriendlyByteBuf.getVarIntSize(this.storage.getSize()) + this.storage.getRaw().length * 8;
}
The this.storage.getSize()
call returns the number of states in storage, which is 4096, instead of the size of the storage array, zero. This allocates an extra byte for the varint. I'm unsure if this can cause bugs for other palette types, but definitely it's calculating a size for a different value than the one being serialized which seems dangerous.
Fixing the bug is trivial, use the same length to calculate the varint as you do to calculate the array size, which is what gets serialized later:
public int getSerializedSize() {
return 1 + this.palette.getSerializedSize() + FriendlyByteBuf.getVarIntSize(this.storage.getRaw().length) + this.storage.getRaw().length * 8;
}
This is similar in nature but distinct from https://bugs.mojang.com/browse/MC-131684
Linked issues
duplicates 1
Comments 2
Resolving as a duplicate of MC-242385. Thanks for your report!
Relates to or duplicates MC-242385.