Skip to content

Commit e532c2e

Browse files
authored
Merge pull request #36 from joshtrichards/patch-1
fix: generate exception if codec/layer versions or channel headers are unrecognized
2 parents d749cdd + 455eb86 commit e532c2e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Mp3Info.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ private function readMpegFrame($fp) {
373373

374374
switch ($header_bytes[1] >> 3 & 0b11) {
375375
case 0b00: $this->codecVersion = self::MPEG_25; break;
376-
case 0b01: $this->codecVersion = self::CODEC_UNDEFINED; break;
377376
case 0b10: $this->codecVersion = self::MPEG_2; break;
378377
case 0b11: $this->codecVersion = self::MPEG_1; break;
379378
}
@@ -384,6 +383,9 @@ private function readMpegFrame($fp) {
384383
case 0b11: $this->layerVersion = self::LAYER_1; break;
385384
}
386385

386+
if (!isset($this->codecVersion) || !isset($this->layerVersion) || !isset($header_bytes[2])) {
387+
throw new \Exception('Unrecognized codecVersion or layerVersion headers!');
388+
}
387389
$this->bitRate = self::$_bitRateTable[$this->codecVersion][$this->layerVersion][$header_bytes[2] >> 4];
388390
$this->sampleRate = self::$_sampleRateTable[$this->codecVersion][($header_bytes[2] >> 2) & 0b11];
389391

@@ -394,6 +396,9 @@ private function readMpegFrame($fp) {
394396
case 0b11: $this->channel = self::MONO; break;
395397
}
396398

399+
if (!isset($this->channel)) {
400+
throw new \Exception('Unrecognized channel header!');
401+
}
397402
$vbr_offset = self::$_vbrOffsets[$this->codecVersion][$this->channel == self::MONO ? 0 : 1];
398403

399404
// check for VBR

0 commit comments

Comments
 (0)