wp/wp-includes/ID3/module.audio.flac.php
changeset 16 a86126ab1dd4
parent 7 cf61fcea0001
child 19 3d72ae0968f4
--- a/wp/wp-includes/ID3/module.audio.flac.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/ID3/module.audio.flac.php	Tue Dec 15 13:49:49 2020 +0100
@@ -1,11 +1,11 @@
 <?php
+
 /////////////////////////////////////////////////////////////////
 /// getID3() by James Heinrich <info@getid3.org>               //
-//  available at http://getid3.sourceforge.net                 //
-//            or http://www.getid3.org                         //
-//          also https://github.com/JamesHeinrich/getID3       //
-/////////////////////////////////////////////////////////////////
-// See readme.txt for more details                             //
+//  available at https://github.com/JamesHeinrich/getID3       //
+//            or https://www.getid3.org                        //
+//            or http://getid3.sourceforge.net                 //
+//  see readme.txt for more details                            //
 /////////////////////////////////////////////////////////////////
 //                                                             //
 // module.audio.flac.php                                       //
@@ -14,7 +14,9 @@
 //                                                            ///
 /////////////////////////////////////////////////////////////////
 
-
+if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
+	exit;
+}
 getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.ogg.php', __FILE__, true);
 
 /**
@@ -24,6 +26,9 @@
 {
 	const syncword = 'fLaC';
 
+	/**
+	 * @return bool
+	 */
 	public function Analyze() {
 		$info = &$this->getid3->info;
 
@@ -41,22 +46,30 @@
 		return $this->parseMETAdata();
 	}
 
+	/**
+	 * @return bool
+	 */
 	public function parseMETAdata() {
 		$info = &$this->getid3->info;
 		do {
 			$BlockOffset   = $this->ftell();
 			$BlockHeader   = $this->fread(4);
-			$LBFBT         = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1));
+			$LBFBT         = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1));  // LBFBT = LastBlockFlag + BlockType
 			$LastBlockFlag = (bool) ($LBFBT & 0x80);
 			$BlockType     =        ($LBFBT & 0x7F);
 			$BlockLength   = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3));
 			$BlockTypeText = self::metaBlockTypeLookup($BlockType);
 
 			if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) {
-				$this->error('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
+				$this->warning('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
 				break;
 			}
 			if ($BlockLength < 1) {
+				if ($BlockTypeText != 'reserved') {
+					// probably supposed to be zero-length
+					$this->warning('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockTypeText.') at offset '.$BlockOffset.' is zero bytes');
+					continue;
+				}
 				$this->error('METADATA_BLOCK_HEADER.BLOCK_LENGTH ('.$BlockLength.') at offset '.$BlockOffset.' is invalid');
 				break;
 			}
@@ -167,7 +180,7 @@
 		if (isset($info['flac']['STREAMINFO']['audio_signature'])) {
 
 			if ($info['flac']['STREAMINFO']['audio_signature'] === str_repeat("\x00", 16)) {
-                $this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
+				$this->warning('FLAC STREAMINFO.audio_signature is null (known issue with libOggFLAC)');
 			}
 			else {
 				$info['md5_data_source'] = '';
@@ -194,12 +207,14 @@
 		return true;
 	}
 
-	private function parseSTREAMINFO($BlockData) {
-		$info = &$this->getid3->info;
 
-		$info['flac']['STREAMINFO'] = array();
-		$streaminfo = &$info['flac']['STREAMINFO'];
-
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return array
+	 */
+	public static function parseSTREAMINFOdata($BlockData) {
+		$streaminfo = array();
 		$streaminfo['min_block_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 0, 2));
 		$streaminfo['max_block_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 2, 2));
 		$streaminfo['min_frame_size']  = getid3_lib::BigEndian2Int(substr($BlockData, 4, 3));
@@ -211,15 +226,28 @@
 		$streaminfo['bits_per_sample'] = getid3_lib::Bin2Dec(substr($SRCSBSS, 23,  5)) + 1;
 		$streaminfo['samples_stream']  = getid3_lib::Bin2Dec(substr($SRCSBSS, 28, 36));
 
-		$streaminfo['audio_signature'] = substr($BlockData, 18, 16);
+		$streaminfo['audio_signature'] =                           substr($BlockData, 18, 16);
+
+		return $streaminfo;
+	}
 
-		if (!empty($streaminfo['sample_rate'])) {
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return bool
+	 */
+	private function parseSTREAMINFO($BlockData) {
+		$info = &$this->getid3->info;
+
+		$info['flac']['STREAMINFO'] = self::parseSTREAMINFOdata($BlockData);
+
+		if (!empty($info['flac']['STREAMINFO']['sample_rate'])) {
 
 			$info['audio']['bitrate_mode']    = 'vbr';
-			$info['audio']['sample_rate']     = $streaminfo['sample_rate'];
-			$info['audio']['channels']        = $streaminfo['channels'];
-			$info['audio']['bits_per_sample'] = $streaminfo['bits_per_sample'];
-			$info['playtime_seconds']         = $streaminfo['samples_stream'] / $streaminfo['sample_rate'];
+			$info['audio']['sample_rate']     = $info['flac']['STREAMINFO']['sample_rate'];
+			$info['audio']['channels']        = $info['flac']['STREAMINFO']['channels'];
+			$info['audio']['bits_per_sample'] = $info['flac']['STREAMINFO']['bits_per_sample'];
+			$info['playtime_seconds']         = $info['flac']['STREAMINFO']['samples_stream'] / $info['flac']['STREAMINFO']['sample_rate'];
 			if ($info['playtime_seconds'] > 0) {
 				if (!$this->isDependencyFor('matroska')) {
 					$info['audio']['bitrate'] = (($info['avdataend'] - $info['avdataoffset']) * 8) / $info['playtime_seconds'];
@@ -236,6 +264,11 @@
 		return true;
 	}
 
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return bool
+	 */
 	private function parseAPPLICATION($BlockData) {
 		$info = &$this->getid3->info;
 
@@ -246,6 +279,11 @@
 		return true;
 	}
 
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return bool
+	 */
 	private function parseSEEKTABLE($BlockData) {
 		$info = &$this->getid3->info;
 
@@ -275,6 +313,11 @@
 		return true;
 	}
 
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return bool
+	 */
 	private function parseVORBIS_COMMENT($BlockData) {
 		$info = &$this->getid3->info;
 
@@ -294,6 +337,11 @@
 		return true;
 	}
 
+	/**
+	 * @param string $BlockData
+	 *
+	 * @return bool
+	 */
 	private function parseCUESHEET($BlockData) {
 		$info = &$this->getid3->info;
 		$offset = 0;
@@ -346,9 +394,11 @@
 	}
 
 	/**
-	* Parse METADATA_BLOCK_PICTURE flac structure and extract attachment
-	* External usage: audio.ogg
-	*/
+	 * Parse METADATA_BLOCK_PICTURE flac structure and extract attachment
+	 * External usage: audio.ogg
+	 *
+	 * @return bool
+	 */
 	public function parsePICTURE() {
 		$info = &$this->getid3->info;
 
@@ -380,6 +430,11 @@
 		return true;
 	}
 
+	/**
+	 * @param int $blocktype
+	 *
+	 * @return string
+	 */
 	public static function metaBlockTypeLookup($blocktype) {
 		static $lookup = array(
 			0 => 'STREAMINFO',
@@ -393,6 +448,11 @@
 		return (isset($lookup[$blocktype]) ? $lookup[$blocktype] : 'reserved');
 	}
 
+	/**
+	 * @param int $applicationid
+	 *
+	 * @return string
+	 */
 	public static function applicationIDLookup($applicationid) {
 		// http://flac.sourceforge.net/id.html
 		static $lookup = array(
@@ -423,6 +483,11 @@
 		return (isset($lookup[$applicationid]) ? $lookup[$applicationid] : 'reserved');
 	}
 
+	/**
+	 * @param int $type_id
+	 *
+	 * @return string
+	 */
 	public static function pictureTypeLookup($type_id) {
 		static $lookup = array (
 			 0 => 'Other',