Skip to content

Better handling of duplicate CompoundTag keys #101

Open
@dktapps

Description

@dktapps

Currently, a duplicate key appearing anywhere in some NBT data tree will cause the entire tree to be undecodable using this library. This is severely problematic for legacy PM worlds, because the entire chunk is stored as one big NBT blob in MCRegion, Anvil and PMAnvil worlds. This means that any appearance of a duplicated key will cause the entire chunk to be discarded as corrupted.

This issue has caused a large number of worlds created with PM older than ~2017 to lose any chunks containing furnace due to a duplicate BurnTime key (this was originally fixed by pmmp/PocketMine-MP@20b86bd). However, any worlds created before this commit which were not loaded prior to the fix of #54 will now experience full data loss if this happened in any of their chunks, which is not cool.

Possible solutions

  • Go back to the old way, and don't throw errors on duplicate tags - simply allow the last tag with the same name to overwrite the earlier ones - not perfect; someone else like me may consider this a bug in the future and then add a new check and cause the same problem.
  • Keep a list of tags under each name in a compound. This would avoid any loss of data, but would increase implementation complexity for minimal benefit.
  • Accept a user-provided callback to decide what to do.
  • Accept flags to decide what should be done (e.g. NbtSerializer::IGNORE_DUPLICATE_COMPOUND_KEYS).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions