mojira.dev
MC-205224

Dedicated server packet error when too many blocks in a chunk are modified

When using the provided datapack to cut holes in the terrain on a dedicated server, I was disconnected as soon as it started destroying blocks.

Update
I used Fabric to locate the issue and believe it it a lighting issue in LightUpdateS2CPacket. In 1.16.4, the read method in the packed looked like this:

public void read(PacketByteBuf buf) throws IOException {
        this.chunkX = buf.readVarInt();
        this.chunkZ = buf.readVarInt();
        this.field_25659 = buf.readBoolean();
        this.skyLightMask = buf.readVarLong();
        this.blockLightMask = buf.readVarLong();
        this.filledSkyLightMask = buf.readVarLong();
        this.filledBlockLightMask = buf.readVarLong();
        this.skyLightUpdates = Lists.newArrayList();

        int j;
        for(j = 0; j < 18; ++j) {
            if ((this.skyLightMask & 1L << j) != 0L) {
                this.skyLightUpdates.add(buf.readByteArray(2048));
            }
        }

        this.blockLightUpdates = Lists.newArrayList();

        for(j = 0; j < 18; ++j) {
            if ((this.blockLightMask & 1L << j) != 0L) {
                this.blockLightUpdates.add(buf.readByteArray(2048));
            }
        }

    }

Where in the latest snapshot it is

public void read(PacketByteBuf buf) throws IOException {
        this.chunkX = buf.readVarInt();
        this.chunkZ = buf.readVarInt();
        this.field_25659 = buf.readBoolean();
        this.skyLightMask = buf.readVarLong();
        this.blockLightMask = buf.readVarLong();
        this.filledSkyLightMask = buf.readVarLong();
        this.filledBlockLightMask = buf.readVarLong();
        this.skyLightUpdates = Lists.newArrayList();

        int j;
        for(j = 0; j < 64; ++j) {
            if ((this.skyLightMask & 1L << j) != 0L) {
                this.skyLightUpdates.add(buf.readByteArray(2048));
            }
        }

        this.blockLightUpdates = Lists.newArrayList();

        for(j = 0; j < 64; ++j) {
            if ((this.blockLightMask & 1L << j) != 0L) {
                this.blockLightUpdates.add(buf.readByteArray(2048));
            }
        }

    }

The key change here is

for(j = 0; j < 64; ++j)
    if ((this.skyLightMask & 1L << j) != 0L)

which when the condition passes for any value greater than 17, causes too much data to be read from the buffer leading to an exception.

Reverting the change from 64 to 18 using a mixin solved the issue.

Steps to Reproduce:
1. Run a dedicated server with the provided datapack. It appears to work fine in singleplayer.
2. Throw a snowball at some terrain.

Attachments

Comments 0

No comments.

Brandon Silva

Panda4994

Plausible

Very Important

Data Packs, Networking

crash, duplicated-issue, multiplayer, server, world

20w46a, 20w48a

Retrieved