Skip to content

Commit 6d8123e

Browse files
committed
don't accept stings longer than 0xffff
1 parent c0cffc1 commit 6d8123e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Tag/StringTag.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ public function getLength(): int
3939

4040
/**
4141
* @inheritDoc
42+
* @throws \Exception
4243
*/
4344
public function generatePayload(NbtSerializer $serializer): string
4445
{
45-
return $serializer->encodeStringLengthPrefix(strlen($this->value)) . $this->value;
46+
$length = strlen($this->value);
47+
if($length > 0xffff) {
48+
throw new \Exception("String exceeds maximum length of " . 0xffff . " characters");
49+
}
50+
return $serializer->encodeStringLengthPrefix($length) . $this->value;
4651
}
4752

4853
/**

0 commit comments

Comments
 (0)