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

writeString method of PacketBuffer is not creating correct exception text

    XMLWordPrintable

Details

    • Unconfirmed

    Description

      The bug

      When a String whose encoded length is larger than 32767 bytes should be written to a PacketBuffer the message in the exception uses the length of the String instead of the length of the byte array. This results in exceptions like "String too big (was 16000 bytes encoded, max 32767)".

      net.minecraft.network.PacketBuffer.writeString(String) (MCP 9.30, Minecraft 1.10)
      public PacketBuffer writeString(String string)
      {
          byte[] abyte = string.getBytes(Charsets.UTF_8);
      
          if (abyte.length > 32767)
          {
              // Replaced this, uses abyte.length instead of string.length()
              //throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + 32767 + ")");
              throw new EncoderException("String too big (was " + abyte.length + " bytes encoded, max " + 32767 + ")");
          }
          else
          {
              this.writeVarIntToBuffer(abyte.length);
              this.writeBytes(abyte);
              return this;
          }
      }
      

      How to reproduce

      See MC-68458

      Attachments

        Issue Links

          Activity

            People

              grum [Mojang] Grum (Erik Broes)
              marcono1234 [Mod] Marcono1234
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: