From 6d8123ebcd0e5fb73edf748ea1245358cbd7d67d Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Fri, 10 Sep 2021 17:19:16 +0200 Subject: [PATCH] don't accept stings longer than 0xffff --- src/Tag/StringTag.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Tag/StringTag.php b/src/Tag/StringTag.php index e6457b6..2352135 100644 --- a/src/Tag/StringTag.php +++ b/src/Tag/StringTag.php @@ -39,10 +39,15 @@ public function getLength(): int /** * @inheritDoc + * @throws \Exception */ public function generatePayload(NbtSerializer $serializer): string { - return $serializer->encodeStringLengthPrefix(strlen($this->value)) . $this->value; + $length = strlen($this->value); + if($length > 0xffff) { + throw new \Exception("String exceeds maximum length of " . 0xffff . " characters"); + } + return $serializer->encodeStringLengthPrefix($length) . $this->value; } /**