From 7f4f6cdf052f073befb8c80b823d2fb0c5960773 Mon Sep 17 00:00:00 2001 From: kotyaralih <62548070+kotyaralih@users.noreply.github.com> Date: Sun, 5 Dec 2021 09:00:42 -0800 Subject: [PATCH] Halt NBT parsing if end of data is found --- src/utils/NBT.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/utils/NBT.php b/src/utils/NBT.php index b6e79742..7b7481e9 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -43,6 +43,10 @@ class NBT{ $this->offset += $n; return substr($this->binary, $this->offset - $n, $n); } + + private function feof(){ + return !isset($this->binary{$this->offset}); + } public function write($bin){ $this->binary .= $bin; @@ -119,7 +123,7 @@ class NBT{ } private function parseList(&$node, $tag, $cnt){ - for($i = 0; $i < $cnt; ++$i){ + for($i = 0; $i < $cnt and !$this->feof(); ++$i){ switch($tag){ case self::TAG_BYTE: $value = $this->readTAG_BYTE(); @@ -163,7 +167,7 @@ class NBT{ } private function parseTree(&$node){ - while(($tag = ord($this->read(1))) !== self::TAG_END){ + while(($tag = ord($this->read(1))) !== self::TAG_END and !$this->feof()){ $name = $this->readTAG_STRING(); switch($tag){ case self::TAG_BYTE: