sync NBT network string length cap

This commit is contained in:
Dylan K. Taylor 2019-04-14 17:14:44 +01:00
parent 9b0b8b9a0c
commit cfd4580388

View File

@ -46,15 +46,11 @@ class NetworkNbtSerializer extends LittleEndianNbtSerializer{
}
public function readString() : string{
return $this->buffer->get($this->buffer->getUnsignedVarInt());
return $this->buffer->get(self::checkReadStringLength($this->buffer->getUnsignedVarInt()));
}
public function writeString(string $v) : void{
$len = strlen($v);
if($len > 32767){
throw new \InvalidArgumentException("NBT strings cannot be longer than 32767 bytes, got $len bytes");
}
$this->buffer->putUnsignedVarInt($len);
$this->buffer->putUnsignedVarInt(self::checkWriteStringLength(strlen($v)));
$this->buffer->put($v);
}