PlayerExperienceChangeEvent: added range checks to setNewProgress()

WE FINALLY FUCKING FOUND IT

This took several years to identify because PHP's exception stack traces don't show the actual values of parameters, but rather the values of the variables they were assigned to.

This means that if the parameter variable is mutated, the exception trace will show the value of the variable inside the function, not the value that was actually passed.
This commit is contained in:
Dylan K. Taylor 2021-12-10 17:29:57 +00:00
parent 911ad344c9
commit 6d5c463bdd
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 3 additions and 5 deletions

View File

@ -57,7 +57,6 @@ use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\network\mcpe\protocol\types\SkinAdapterSingleton;
use pocketmine\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\UUID;
use function array_filter;
use function array_merge;
@ -70,7 +69,6 @@ use function max;
use function min;
use function mt_rand;
use function random_int;
use function sprintf;
use function strlen;
use const INT32_MAX;
use const INT32_MIN;
@ -397,9 +395,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$xpLevel = (int) $newLevel;
$xpProgress = $newLevel - (int) $newLevel;
if($xpProgress > 1.0){
throw new AssumptionFailedError(sprintf("newLevel - (int) newLevel should never be bigger than 1, but have %.53f (newLevel=%.53f)", $xpProgress, $newLevel));
}
return $this->setXpAndProgress($xpLevel, $xpProgress);
}

View File

@ -79,6 +79,9 @@ class PlayerExperienceChangeEvent extends EntityEvent implements Cancellable{
}
public function setNewProgress(?float $newProgress) : void{
if($newProgress < 0.0 || $newProgress > 1.0){
throw new \InvalidArgumentException("XP progress must be in range 0-1");
}
$this->newProgress = $newProgress;
}
}