mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
Throw a specific exception for zlib decompression failure
This commit is contained in:
parent
35d656c6e5
commit
843993f02b
@ -35,6 +35,7 @@ use pocketmine\form\Form;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\BadPacketException;
|
||||
use pocketmine\network\mcpe\compression\CompressBatchPromise;
|
||||
use pocketmine\network\mcpe\compression\DecompressionException;
|
||||
use pocketmine\network\mcpe\compression\Zlib;
|
||||
use pocketmine\network\mcpe\encryption\DecryptionException;
|
||||
use pocketmine\network\mcpe\encryption\NetworkCipher;
|
||||
@ -280,7 +281,7 @@ class NetworkSession{
|
||||
Timings::$playerNetworkReceiveDecompressTimer->startTiming();
|
||||
try{
|
||||
$stream = new PacketBatch(Zlib::decompress($payload));
|
||||
}catch(\ErrorException $e){
|
||||
}catch(DecompressionException $e){
|
||||
$this->logger->debug("Failed to decompress packet: " . base64_encode($payload));
|
||||
//TODO: this isn't incompatible game version if we already established protocol version
|
||||
throw BadPacketException::wrap($e, "Compressed packet batch decode error");
|
||||
|
28
src/network/mcpe/compression/DecompressionException.php
Normal file
28
src/network/mcpe/compression/DecompressionException.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\compression;
|
||||
|
||||
final class DecompressionException extends \RuntimeException{
|
||||
|
||||
}
|
@ -40,10 +40,14 @@ final class Zlib{
|
||||
/**
|
||||
* @param int $maxDecodedLength default 2MB
|
||||
*
|
||||
* @throws \ErrorException
|
||||
* @throws DecompressionException
|
||||
*/
|
||||
public static function decompress(string $payload, int $maxDecodedLength = 1024 * 1024 * 2) : string{
|
||||
return zlib_decode($payload, $maxDecodedLength);
|
||||
$result = @zlib_decode($payload, $maxDecodedLength);
|
||||
if($result === false){
|
||||
throw new DecompressionException("Failed to decompress data");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user