mojira.dev
MC-98180

Sending a null header or footer results in an NPE/Unable to remove headers/footers from the player list

Sending a null header or footer value when sending packet 0x47 will result in an NPE, due to the value not being checked before being turned into a formatted string:

public void handlePlayerListHeaderFooter(S47PacketPlayerListHeaderFooter packetIn)
    {
        this.gameController.ingameGUI.getTabList().setHeader(packetIn.getHeader().getFormattedText().length() == 0 ? null : packetIn.getHeader());
        this.gameController.ingameGUI.getTabList().setFooter(packetIn.getFooter().getFormattedText().length() == 0 ? null : packetIn.getFooter());
    }

The formatted text length is never zero - getFormattedText adds §r even if the provided text is empty - which means that there is no way to remove the header or footer, just make empty text/§r appear. Sending null, if it didn't call getFormattedText first, would work as intended.

Comments 6

Well, don't send null then.

Could you explain why you marked this as invalid? The formatted text length is never zero - getFormattedText adds §r even if the provided text is empty - which means that there is no way to remove the header or footer, just make empty text/§r appear.

Cannot confirm for 1.11.2 using MCP 9.35

Are you getting a NullPointerException or a DecoderException because the constructor of that packet is faulty and is missing the footer parameter?
When I send this packet (without a footer) from a server I get a DecoderException because the packet tries to turn null into a JSON String. In a singleplayer world I get a NullPointerException, I am not sure where exactly that happens but that is probably not that important.

After adding a footer parameter to the constructor the packet is sent fine and removes header and / or footer if the text is empty.

Starting with Minecraft 1.9 (and most likely 1.9 snapshots) text components are not directly deserialised - instead they pass through a non-lenient `JsonReader`. When sending a `null` header and footer from a server to a vanilla client, this exception occurs:
When using the lenient deserialiser: https://gist.github.com/kashike/ce389d81d105cbf2b1c484e12ab30160
When using the same deserialisation (`GSON.fromJson`) as 1.8: https://gist.github.com/kashike/82489e367750fa70825d3d91f772de48

The issue introduced with 1.9 makes it impossible to send a `null` `Component`, further removing the ability to *remove* the header and/or footer - it is still only possible to make it empty (due to it calling `getFormattedText`, which `isEmpty` is *never* true on), as described earlier in the issue.
The original issue here still remains and is still within the client packet listener, due to it calling `getFormattedText` on a null `Component`:

// SRG: func_175096_a
    public void handlePlayerListHeaderFooter(SPacketPlayerListHeaderFooter packetIn) {
        this.gameController.ingameGUI.getTabList().setHeader(packetIn.getHeader().getFormattedText().isEmpty() ? null : packetIn.getHeader());
        this.gameController.ingameGUI.getTabList().setFooter(packetIn.getFooter().getFormattedText().isEmpty() ? null : packetIn.getFooter());
    }

I guess you can consider it a bug that the server is able to serialize null in the first place.

However, I just tried it now with a modified server and an unmodified 1.11.2 client and I was able to clear header and footer when sending an empty string text component. Are you sure you are sending both, head and footer and both are not null?

Apparently actually fixed in 1.11.1, and not 1.11.2. @unknown doesn't remember why 1.11.2 was added. (checked and manually confirmed that a fix was present in 1.11.1 and not 1.11.0)

Riley Park

(Unassigned)

Unconfirmed

footer, header, null, player-list, server

Minecraft 1.8.9, Minecraft 1.9 Pre-Release 4, Minecraft 1.9, Minecraft 1.10.2, Minecraft 1.11 Pre-Release 1, Minecraft 1.11.2

Minecraft 1.11.1

Retrieved