Skip to content

Commit

Permalink
fix: Freezing by malicious packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Gewinum committed Jul 3, 2024
1 parent 972373b commit 82c739e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/EmoteListPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public function getEmoteIds() : array{ return $this->emoteIds; }
protected function decodePayload(PacketSerializer $in) : void{
$this->playerActorRuntimeId = $in->getActorRuntimeId();
$this->emoteIds = [];
for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
$len = $in->getUnsignedVarInt();

// While EmoteListPacket doesn't really freeze the server, its abusing can increase server load by 10-20%
if($len > 100){
throw new PacketDecodeException("Too many emote ids");
}

for($i = 0; $i < $len; ++$i){
$this->emoteIds[] = $in->getUUID();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/PurchaseReceiptPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public static function create(array $entries) : self{

protected function decodePayload(PacketSerializer $in) : void{
$count = $in->getUnsignedVarInt();

if($count > 50) {
throw new PacketDecodeException("Too many entries");
}

for($i = 0; $i < $count; ++$i){
$this->entries[] = $in->getString();
}
Expand Down
3 changes: 3 additions & 0 deletions src/ResourcePackClientResponsePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static function create(int $status, array $packIds) : self{
protected function decodePayload(PacketSerializer $in) : void{
$this->status = $in->getByte();
$entryCount = $in->getLShort();
if($entryCount > 100) {
throw new PacketDecodeException("Too many pack ids");
}
$this->packIds = [];
while($entryCount-- > 0){
$this->packIds[] = $in->getString();
Expand Down
5 changes: 5 additions & 0 deletions src/TextPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ protected function decodePayload(PacketSerializer $in) : void{
case self::TYPE_JUKEBOX_POPUP:
$this->message = $in->getString();
$count = $in->getUnsignedVarInt();

if($count > 20) {
throw new PacketDecodeException("Too many parameters");
}

for($i = 0; $i < $count; ++$i){
$this->parameters[] = $in->getString();
}
Expand Down

0 comments on commit 82c739e

Please sign in to comment.