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

NBT is partially deserialized if it contains an invalid resource location

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.15 Pre-Release 2, 1.15 Pre-release 5, 1.15 Pre-release 6, 1.15.2, 20w06a, 20w07a, 20w08a, 20w09a, 20w10a, 20w11a, 20w12a, 20w14a, 20w16a, 20w17a, 20w18a, 20w20b, 1.16 Pre-release 5, 1.16.1, 1.16.2 Pre-release 1, 1.16.2, 1.16.3, 1.16.4 Pre-release 1, 1.16.4, 20w45a, 20w46a, 20w48a, 20w49a, 20w51a, 21w03a, 1.16.5, 1.17.1, 21w37a, 1.19.1, 1.19.2, 1.19.3 Release Candidate 1, 1.19.4, 23w18a, 1.20.2
    • Confirmed
    • Commands
    • Low
    • Platform

      The bug

      If NBT contains an invalid resource location, it will be partially deserialized. This is a confusing behavior because the deserialization result depends on the internal implementation (deserialization order).

      How to reproduce

      1. /setblock 0 0 0 minecraft:jigsaw{name: "a", target: "!", pool: "b"}

        An unexpected error occurred trying to execute that command (Non [a-z0-9/._-] character in path of location: minecraft:!)

      2. /data get block 0 0 0 name

        0, 0, 0 has the following block data: "minecraft:a" (changed)

      3. /data get block 0 0 0 target

        0, 0, 0 has the following block data: "minecraft:empty" (unchanged)

      4. /data get block 0 0 0 pool

        0, 0, 0 has the following block data: "minecraft:empty" (unchanged)

      Code analysis

      The constructor of ResourceLocation throws ResourceLocationException if an invalid location string is passed. Any deserializations that ResourceLocation is instantiated with an arbitrary string can be exited after partially modifying the fields.

      // net.minecraft.world.level.block.entity.JigsawBlockEntity
      
      public void load(BlockState state, CompoundTag tag) {
          // ...
          
          name = new ResourceLocation(tag.getString("name"));
          target = new ResourceLocation(tag.getString("target"));
          pool = new ResourceLocation(tag.getString("pool"));
      
          // ...
      }
      
      

            Unassigned Unassigned
            intsuc intsuc
            Votes:
            7 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              CHK: