Skip to content

Commit

Permalink
don't accept stings longer than 0xffff
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Sep 10, 2021
1 parent c0cffc1 commit 6d8123e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Tag/StringTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 6d8123e

Please sign in to comment.