mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 06:55:29 +00:00
Throw exceptions when failing to deserialize item NBT data, fixed weird crashes when an invalid NBT tag is set on an item
This commit is contained in:
parent
1c3d89cfef
commit
bc1c75a15a
@ -46,12 +46,22 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
private static $cachedParser = null;
|
private static $cachedParser = null;
|
||||||
|
|
||||||
private static function parseCompoundTag(string $tag) : CompoundTag{
|
private static function parseCompoundTag(string $tag) : CompoundTag{
|
||||||
|
if(strlen($tag) === 0){
|
||||||
|
throw new \InvalidArgumentException("No NBT data found in supplied string");
|
||||||
|
}
|
||||||
|
|
||||||
if(self::$cachedParser === null){
|
if(self::$cachedParser === null){
|
||||||
self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN);
|
self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$cachedParser->read($tag);
|
self::$cachedParser->read($tag);
|
||||||
return self::$cachedParser->getData();
|
$data = self::$cachedParser->getData();
|
||||||
|
|
||||||
|
if(!($data instanceof CompoundTag)){
|
||||||
|
throw new \InvalidArgumentException("Invalid item NBT string given, it could not be deserialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function writeCompoundTag(CompoundTag $tag) : string{
|
private static function writeCompoundTag(CompoundTag $tag) : string{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user