mojira.dev
MC-259282

NBT strings that exceed the length limit can be created

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)

Linked issues

Attachments

Comments 0

No comments.

intsuc

(Unassigned)

Confirmed

Commands, Save Data

nbt

1.19.3, 23w03a

Retrieved