Skip to content

fix: remove length limit for WrapperPlayClientPluginMessage#1502

Open
Kowagirl wants to merge 1 commit into
retrooper:2.0from
Kowagirl:2.0
Open

fix: remove length limit for WrapperPlayClientPluginMessage#1502
Kowagirl wants to merge 1 commit into
retrooper:2.0from
Kowagirl:2.0

Conversation

@Kowagirl

@Kowagirl Kowagirl commented Apr 24, 2026

Copy link
Copy Markdown

Closes #1133

This packet may be larger than 32767 bytes:

The vanilla server enforces a length limit of 32767 bytes on this data, but only if the channel type is unrecognized.

https://minecraft.wiki/w/Java_Edition_protocol/Packets#Serverbound_Plugin_Message_(play)

@Kowagirl Kowagirl changed the title fix: remove length limit on custom_payload fix: remove length limit on WrapperPlayClientPluginMessage Apr 24, 2026
@Kowagirl Kowagirl changed the title fix: remove length limit on WrapperPlayClientPluginMessage fix: remove length limit for WrapperPlayClientPluginMessage Apr 24, 2026
@Kowagirl Kowagirl marked this pull request as draft April 24, 2026 09:38
@Kowagirl

Kowagirl commented Apr 24, 2026

Copy link
Copy Markdown
Author

Don't merge, doing some investigation first.

@Kowagirl Kowagirl marked this pull request as ready for review April 26, 2026 03:36
@Kowagirl

Kowagirl commented Apr 26, 2026

Copy link
Copy Markdown
Author

@retrooper The issue I was encountering was due to NuVotifier/NuVotifier#344, but this PR did help me diagnose it, so it might be worth merging. I also checked the NMS code and I think the server will always reject the packet if it is above the limit, I'm not sure where the docs are getting that from:

ServerboundCustomPayloadPacket.java

    public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.<FriendlyByteBuf>codec(
            id -> DiscardedPayload.codec(id, 32767),
            java.util.Collections.emptyList() // CraftBukkit - treat all packets the same
        )
        .map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);

DiscardedPayload.java

    public static <T extends FriendlyByteBuf> StreamCodec<T, DiscardedPayload> codec(Identifier id, int maxSize) {
        return CustomPacketPayload.codec((value, output) -> {
            // Paper start
            // Always write data
            output.writeBytes(value.data);
        }, buffer -> {
            int i = buffer.readableBytes();
            if (i >= 0 && i <= maxSize) {
                final byte[] data = new byte[i];
                buffer.readBytes(data);
                return new DiscardedPayload(id, data);
                // Paper end
            } else {
                throw new IllegalArgumentException("Payload may not be larger than " + maxSize + " bytes");
            }
        });
    }

Your call on if this should be merged. At the very least it would stop folks from making a PacketEvents (or plugin that uses PacketEvents) issue when they see the console error, and will give a way for devs to debug which plugin is actually producing the oversized packet.

Alternatively we could include the channelName and data size in the error message from PacketEvents and still throw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Payload may not be larger than 32767 bytes

1 participant