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

NBT strings that exceed the length limit can be created

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • None
    • 1.19.3, 23w03a
    • Confirmed
    • Commands, Save Data

      The bug

      The maximum length of the NBT string that can be properly saved is 65535 bytes due to the limitation of java.io.DataOutput#writeUTF. If the length of the NBT string exceeds this limit, an error message is displayed when trying to save, and an empty string ("") is saved instead.

      However, since no length check is performed when creating an NBT string, it is possible to freely create an NBT string that cannot be saved properly. While this behavior is convenient because we can work with strings of virtually unlimited length in memory, it is also confusing.

      How to reproduce

      1. Run the following command (the full command is in Attachments)
        data modify storage mc-259282: _ set value "⛏⛏…⛏"
        

        Modified storage mc-259282:

      2. Save the game →
        Failed to write NBT String
        java.io.UTFDataFormatException: encoded string (⛏⛏⛏⛏⛏⛏⛏⛏...⛏⛏⛏⛏⛏⛏⛏⛏) too long: 65538 bytes
        	at java.base/java.io.DataOutputStream.writeUTF(DataOutputStream.java:369)
        	at java.base/java.io.DataOutputStream.writeUTF(DataOutputStream.java:333)
        	at rg.a(SourceFile:83)
        	at qp.a(SourceFile:487)
        	at qp.a(SourceFile:165)
        	at qp.a(SourceFile:487)
        	at qp.a(SourceFile:165)
        	at qp.a(SourceFile:487)
        	at qp.a(SourceFile:165)
        	at qp.a(SourceFile:487)
        	at qp.a(SourceFile:165)
        	at qz.a(SourceFile:134)
        	at qz.a(SourceFile:99)
        	at qz.a(SourceFile:60)
        	at qz.a(SourceFile:54)
        	at dvd.a(SourceFile:40)
        	at dvo.b(SourceFile:122)
        	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
        	at dvo.a(SourceFile:120)
        	at ahw.as(SourceFile:784)
        	at ahw.a(SourceFile:766)
        	at net.minecraft.server.MinecraftServer.a(SourceFile:538)
        	at net.minecraft.server.MinecraftServer.b(SourceFile:562)
        	at ftc.a(SourceFile:87)
        	at net.minecraft.server.MinecraftServer.w(SourceFile:676)
        	at net.minecraft.server.MinecraftServer.a(SourceFile:264)
        	at java.base/java.lang.Thread.run(Thread.java:833)
        

            Unassigned Unassigned
            intsuc intsuc
            Votes:
            5 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: