From 7c4582dc74798e893e537ae6438560f489336c2c Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 29 Mar 2024 17:05:16 -0400 Subject: [PATCH 1/3] fix: generate exception if codec or layer versions are unrecognized --- src/Mp3Info.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mp3Info.php b/src/Mp3Info.php index 257b147..70ba964 100644 --- a/src/Mp3Info.php +++ b/src/Mp3Info.php @@ -384,6 +384,9 @@ private function readMpegFrame($fp) { case 0b11: $this->layerVersion = self::LAYER_1; break; } + if (!isset($this->codecVersion) || !isset($this->layerVersion) || !isset($header_bytes[2])) { + throw new \Exception('Unknown codecVersion or layerVersion!'); + } $this->bitRate = self::$_bitRateTable[$this->codecVersion][$this->layerVersion][$header_bytes[2] >> 4]; $this->sampleRate = self::$_sampleRateTable[$this->codecVersion][($header_bytes[2] >> 2) & 0b11]; From 694c3de06d21a25bb10cf1fbb78ed6c4e0170a45 Mon Sep 17 00:00:00 2001 From: Josh Date: Fri, 29 Mar 2024 17:13:11 -0400 Subject: [PATCH 2/3] fix: unrecognized channel header --- src/Mp3Info.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mp3Info.php b/src/Mp3Info.php index 70ba964..6ebbc2d 100644 --- a/src/Mp3Info.php +++ b/src/Mp3Info.php @@ -385,7 +385,7 @@ private function readMpegFrame($fp) { } if (!isset($this->codecVersion) || !isset($this->layerVersion) || !isset($header_bytes[2])) { - throw new \Exception('Unknown codecVersion or layerVersion!'); + throw new \Exception('Unrecognized codecVersion or layerVersion headers!'); } $this->bitRate = self::$_bitRateTable[$this->codecVersion][$this->layerVersion][$header_bytes[2] >> 4]; $this->sampleRate = self::$_sampleRateTable[$this->codecVersion][($header_bytes[2] >> 2) & 0b11]; @@ -397,6 +397,9 @@ private function readMpegFrame($fp) { case 0b11: $this->channel = self::MONO; break; } + if (!isset($this->channel)) { + throw new \Exception('Unrecognized channel header!'); + } $vbr_offset = self::$_vbrOffsets[$this->codecVersion][$this->channel == self::MONO ? 0 : 1]; // check for VBR From 455eb86560013ed641d91cb4bc37c96e1b17f324 Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 29 Jun 2024 18:54:38 -0400 Subject: [PATCH 3/3] fix(mp3info): Drop CODEC_UNDEFINED which is invalid --- src/Mp3Info.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Mp3Info.php b/src/Mp3Info.php index 6ebbc2d..17e4074 100644 --- a/src/Mp3Info.php +++ b/src/Mp3Info.php @@ -373,7 +373,6 @@ private function readMpegFrame($fp) { switch ($header_bytes[1] >> 3 & 0b11) { case 0b00: $this->codecVersion = self::MPEG_25; break; - case 0b01: $this->codecVersion = self::CODEC_UNDEFINED; break; case 0b10: $this->codecVersion = self::MPEG_2; break; case 0b11: $this->codecVersion = self::MPEG_1; break; }