Skip to content

Commit

Permalink
Fixed several crashes on bad data due to inadequate TAG_List type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Apr 19, 2022
1 parent d9d02d5 commit 5a98b08
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/block/tile/ContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ trait ContainerTrait{
abstract public function getRealInventory();

protected function loadItems(CompoundTag $tag) : void{
if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag){
if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){
$inventory = $this->getRealInventory();
$listeners = $inventory->getListeners()->toArray();
$inventory->getListeners()->remove(...$listeners); //prevent any events being fired by initialization
Expand Down
3 changes: 2 additions & 1 deletion src/item/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use pocketmine\block\utils\DyeColor;
use pocketmine\data\bedrock\BannerPatternTypeIdMap;
use pocketmine\data\bedrock\DyeColorIdMap;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use function count;
Expand Down Expand Up @@ -98,7 +99,7 @@ protected function deserializeCompoundTag(CompoundTag $tag) : void{
$colorIdMap = DyeColorIdMap::getInstance();
$patternIdMap = BannerPatternTypeIdMap::getInstance();
$patterns = $tag->getListTag(self::TAG_PATTERNS);
if($patterns !== null){
if($patterns !== null && $patterns->getTagType() === NBT::TAG_Compound){
/** @var CompoundTag $t */
foreach($patterns as $t){
$patternColor = $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK(); //TODO: missing pattern colour should be an error
Expand Down
4 changes: 2 additions & 2 deletions src/item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ protected function deserializeCompoundTag(CompoundTag $tag) : void{

$this->canPlaceOn = [];
$canPlaceOn = $tag->getListTag("CanPlaceOn");
if($canPlaceOn !== null){
if($canPlaceOn !== null && $canPlaceOn->getTagType() === NBT::TAG_String){
/** @var StringTag $entry */
foreach($canPlaceOn as $entry){
$this->canPlaceOn[$entry->getValue()] = $entry->getValue();
}
}
$this->canDestroy = [];
$canDestroy = $tag->getListTag("CanDestroy");
if($canDestroy !== null){
if($canDestroy !== null && $canDestroy->getTagType() === NBT::TAG_String){
/** @var StringTag $entry */
foreach($canDestroy as $entry){
$this->canDestroy[$entry->getValue()] = $entry->getValue();
Expand Down

0 comments on commit 5a98b08

Please sign in to comment.