Skip to content

Commit

Permalink
CompoundTag: quietly ignore repeated keys, instead of throwing
Browse files Browse the repository at this point in the history
this isn't ideal, but we don't have much of a choice; many chunks in very old PM worlds are affected by the furnace bug (basically any chunk with a furnace);
we have no other way to avoid losing the entire chunk to corruption errors
  • Loading branch information
dktapps committed Dec 16, 2021
1 parent f6de897 commit 3e0d9ef
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tag/CompoundTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace pocketmine\nbt\tag;

use pocketmine\nbt\NBT;
use pocketmine\nbt\NbtDataException;
use pocketmine\nbt\NbtStreamReader;
use pocketmine\nbt\NbtStreamWriter;
use pocketmine\nbt\NoSuchTagException;
Expand Down Expand Up @@ -292,7 +291,12 @@ public static function read(NbtStreamReader $reader, ReaderTracker $tracker) : s
$name = $reader->readString();
$tag = NBT::createTag($type, $reader, $tracker);
if($result->getTag($name) !== null){
throw new NbtDataException("Duplicate key \"$name\"");
//this is technically a corruption case, but it's very common on older PM worlds (pretty much every
//furnace in PM worlds prior to 2017 is affected), and since we can't extricate this borked data
//from the rest in Anvil/McRegion worlds, we can't barf on this - it would result in complete loss
//of the chunk.
//TODO: add a flag to enable throwing on this (strict mode)
continue;
}
$result->setTag($name, $tag);
}
Expand Down

0 comments on commit 3e0d9ef

Please sign in to comment.