Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-259376

ServerboundMovePlayerPacket's xRot can have invalid value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 24w36a
    • 1.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
    • Plausible
    • Commands
    • Low
    • Platform

      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));
      }
      

        1. impossible-action.png
          1.05 MB
          LemonCaramel
        2. MC-259376.mp4
          5.73 MB
          LemonCaramel

            Unassigned Unassigned
            LemonCaramel LemonCaramel
            Votes:
            7 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: