Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-182438

StorageKey breaks NBT specification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.21.10.22 Preview, 1.20.81 Hotfix
    • None
    • Plausible
    • Windows

      In Bedrock world save data, entities are written to NBT. They have a compound called internalComponents, which contains a compound called EntityStorageKeyComponent, which contains a value called StorageKey.

      This value is 8 bytes long, and it appears to be two 32-bit integers. The appropriate tag type for this value would be a long or byte array, or perhaps two ints. The actual tag type used by the game is string.

      This breaks the NBT spec, since strings are (modified) UTF-8, and 8 random bytes does not constitute a UTF-8 string. For example, 0x0000000400000080, a value I found in an entity in a world of mine, is not UTF-8. It's also worth pointing out that the presence of null bytes in a string payload breaks the spec anyway, see the "(modified)" note for more details.

      The consequences of this is that compliant NBT parsers are unable to properly parse and round-trip this kind of entity NBT data. Addressing this involves weakening validation and type safety by allowing NBT strings to be any arbitrary sequence of bytes, instead of what they are; strings. There's already a tag type representing an arbitrary sequence of bytes – the byte array, so it's inappropriate to use a string for this purpose.

      Bedrock already breaks the spec in at least three other ways (being little-endian, putting a header at the start of level.dat files, and writing blobs sequentially), and you could even argue that there is no formal spec for NBT, but I think it's important that this format works consistently across the two different versions of the game, since it has largely the same purpose.

            tryashtar [Mod] tryashtar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: