Add empty checking for readbytes and headerBytes

This commit is contained in:
ryanrigby17 2018-09-04 14:20:45 +10:00
parent 27bb2c55e9
commit f4b5dd58e7

View File

@ -265,7 +265,7 @@ class Mp3Info {
} while (ftell($fp) < $limit_pos);
}
if ($headerBytes[0] !== 0xFF || (($headerBytes[1] >> 5) & 0b111) != 0b111) throw new \Exception("At 0x".$pos."(".dechex($pos).") should be the first frame header!");
if (empty($headerBytes) || $headerBytes[0] !== 0xFF || (($headerBytes[1] >> 5) & 0b111) != 0b111) throw new \Exception("At 0x".$pos."(".dechex($pos).") should be the first frame header!");
switch ($headerBytes[1] >> 3 & 0b11) {
case 0b10: $this->codecVersion = self::MPEG_2; break;
@ -317,6 +317,7 @@ class Mp3Info {
private function readBytes($fp, $n) {
$raw = fread($fp, $n);
$bytes = array();
if (empty($raw)) return $bytes;
for($i = 0; $i < $n; $i++) $bytes[$i] = ord($raw[$i]);
return $bytes;
}