Mojira Archive
MC-259376

ServerboundMovePlayerPacket's xRot can have invalid value

The Bug

ServerboundMovePlayerPacket's xRot can have invalid(90 over or -90 under) value.

An xRot value greater than 90 or less than -90 is an xRot value that players cannot have.

 

Can check it enter the command

/tp @s ~ ~ ~ ~ -180

or look at the sky and enter the command

/tp @s ~ ~ ~ ~ ~-5

In special cases, the client can also cause packet spam. (ex. send -95 to the server and immediately send -90)

Code analysis

net.minecraft.client.multiplayer.ClientPacketListener
@Override
public void handleMovePlayer(ClientboundPlayerPositionPacket packet) {
    // ...

    localPlayer.setPos(d1, d3, d5);
    localPlayer.setDeltaMovement(d0, d2, d4);
    float f = packet.getYRot();
    float f1 = packet.getXRot();

    if (packet.getRelativeArguments().contains(ClientboundPlayerPositionPacket.RelativeArgument.X_ROT)) {
        // If the player's current xRot is -90 and the "float f1" is -1, the player's xRot will be -91.
        // and the client sends -91 to the server.
        localPlayer.setXRot(localPlayer.getXRot() + f1);
        localPlayer.xRotO += f1;
        // fix example (this would not be a good way)
        // localPlayer.setXRot(Mth.clamp(localPlayer.getXRot() + f1, -90.0F, 90.0F));
        // localPlayer.xRotO = Mth.clamp(localPlayer.xRotO + f1, -90.0F, 90.0F);
    } else {
        // It's the same.
        localPlayer.setXRot(f1);
        localPlayer.xRotO = f1;
    }

    // ...

    this.connection.send(new ServerboundAcceptTeleportationPacket(packet.getId()));
    this.connection.send(new ServerboundMovePlayerPacket.PosRot(localPlayer.getX(), localPlayer.getY(), localPlayer.getZ(), localPlayer.getYRot(), localPlayer.getXRot(), false));
}

Fixed

LemonCaramel

2023-01-24, 07:25 PM

2024-09-14, 12:34 PM

2024-09-14, 12:34 PM

7

9

Plausible

Low

Platform

Commands

chat, pitch, teleport, tp

1.19.3 - 1.20.41.19.3, 23w04a, 1.19.4 Pre-release 1, 1.19.4 Pre-release 3, 1.19.4 Pre-release 4, 1.19.4, 23w14a, 23w16a, 23w17a, 1.20 Pre-release 1, 1.20.1, 23w32a, 1.20.2, 23w40a, 1.20.4

24w36a