wp/wp-includes/ID3/module.audio-video.flv.php
changeset 16 a86126ab1dd4
parent 7 cf61fcea0001
child 19 3d72ae0968f4
--- a/wp/wp-includes/ID3/module.audio-video.flv.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/ID3/module.audio-video.flv.php	Tue Dec 15 13:49:49 2020 +0100
@@ -1,15 +1,22 @@
 <?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       //
+//  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-video.flv.php                                  //
+// module for analyzing Shockwave Flash Video files            //
+// dependencies: NONE                                          //
+//                                                             //
+/////////////////////////////////////////////////////////////////
 //                                                             //
 //  FLV module by Seth Kaufman <sethØwhirl-i-gig*com>          //
 //                                                             //
 //  * version 0.1 (26 June 2005)                               //
 //                                                             //
-//                                                             //
 //  * version 0.1.1 (15 July 2005)                             //
 //  minor modifications by James Heinrich <info@getid3.org>    //
 //                                                             //
@@ -43,15 +50,13 @@
 //  handle GETID3_FLV_VIDEO_VP6FLV_ALPHA                       //
 //  improved AVCSequenceParameterSetReader::readData()         //
 //    by Xander Schouwerwou <schouwerwouØgmail*com>            //
-//                                                             //
-/////////////////////////////////////////////////////////////////
-//                                                             //
-// module.audio-video.flv.php                                  //
-// module for analyzing Shockwave Flash Video files            //
-// dependencies: NONE                                          //
 //                                                            ///
 /////////////////////////////////////////////////////////////////
 
+if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
+	exit;
+}
+
 define('GETID3_FLV_TAG_AUDIO',          8);
 define('GETID3_FLV_TAG_VIDEO',          9);
 define('GETID3_FLV_TAG_META',          18);
@@ -73,12 +78,21 @@
 define('H264_PROFILE_HIGH444',            144);
 define('H264_PROFILE_HIGH444_PREDICTIVE', 244);
 
-class getid3_flv extends getid3_handler {
-
+class getid3_flv extends getid3_handler
+{
 	const magic = 'FLV';
 
-	public $max_frames = 100000; // break out of the loop if too many frames have been scanned; only scan this many if meta frame does not contain useful duration
+	/**
+	 * Break out of the loop if too many frames have been scanned; only scan this
+	 * many if meta frame does not contain useful duration.
+	 *
+	 * @var int
+	 */
+	public $max_frames = 100000;
 
+	/**
+	 * @return bool
+	 */
 	public function Analyze() {
 		$info = &$this->getid3->info;
 
@@ -332,7 +346,11 @@
 		return true;
 	}
 
-
+	/**
+	 * @param int $id
+	 *
+	 * @return string|false
+	 */
 	public static function audioFormatLookup($id) {
 		static $lookup = array(
 			0  => 'Linear PCM, platform endian',
@@ -355,6 +373,11 @@
 		return (isset($lookup[$id]) ? $lookup[$id] : false);
 	}
 
+	/**
+	 * @param int $id
+	 *
+	 * @return int|false
+	 */
 	public static function audioRateLookup($id) {
 		static $lookup = array(
 			0 =>  5500,
@@ -365,6 +388,11 @@
 		return (isset($lookup[$id]) ? $lookup[$id] : false);
 	}
 
+	/**
+	 * @param int $id
+	 *
+	 * @return int|false
+	 */
 	public static function audioBitDepthLookup($id) {
 		static $lookup = array(
 			0 =>  8,
@@ -373,6 +401,11 @@
 		return (isset($lookup[$id]) ? $lookup[$id] : false);
 	}
 
+	/**
+	 * @param int $id
+	 *
+	 * @return string|false
+	 */
 	public static function videoCodecLookup($id) {
 		static $lookup = array(
 			GETID3_FLV_VIDEO_H263         => 'Sorenson H.263',
@@ -386,47 +419,84 @@
 	}
 }
 
-class AMFStream {
+class AMFStream
+{
+	/**
+	 * @var string
+	 */
 	public $bytes;
+
+	/**
+	 * @var int
+	 */
 	public $pos;
 
+	/**
+	 * @param string $bytes
+	 */
 	public function __construct(&$bytes) {
 		$this->bytes =& $bytes;
 		$this->pos = 0;
 	}
 
-	public function readByte() {
-		return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
+	/**
+	 * @return int
+	 */
+	public function readByte() { //  8-bit
+		return ord(substr($this->bytes, $this->pos++, 1));
 	}
 
-	public function readInt() {
+	/**
+	 * @return int
+	 */
+	public function readInt() { // 16-bit
 		return ($this->readByte() << 8) + $this->readByte();
 	}
 
-	public function readLong() {
+	/**
+	 * @return int
+	 */
+	public function readLong() { // 32-bit
 		return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
 	}
 
+	/**
+	 * @return float|false
+	 */
 	public function readDouble() {
 		return getid3_lib::BigEndian2Float($this->read(8));
 	}
 
+	/**
+	 * @return string
+	 */
 	public function readUTF() {
 		$length = $this->readInt();
 		return $this->read($length);
 	}
 
+	/**
+	 * @return string
+	 */
 	public function readLongUTF() {
 		$length = $this->readLong();
 		return $this->read($length);
 	}
 
+	/**
+	 * @param int $length
+	 *
+	 * @return string
+	 */
 	public function read($length) {
 		$val = substr($this->bytes, $this->pos, $length);
 		$this->pos += $length;
 		return $val;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function peekByte() {
 		$pos = $this->pos;
 		$val = $this->readByte();
@@ -434,6 +504,9 @@
 		return $val;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function peekInt() {
 		$pos = $this->pos;
 		$val = $this->readInt();
@@ -441,6 +514,9 @@
 		return $val;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function peekLong() {
 		$pos = $this->pos;
 		$val = $this->readLong();
@@ -448,6 +524,9 @@
 		return $val;
 	}
 
+	/**
+	 * @return float|false
+	 */
 	public function peekDouble() {
 		$pos = $this->pos;
 		$val = $this->readDouble();
@@ -455,6 +534,9 @@
 		return $val;
 	}
 
+	/**
+	 * @return string
+	 */
 	public function peekUTF() {
 		$pos = $this->pos;
 		$val = $this->readUTF();
@@ -462,6 +544,9 @@
 		return $val;
 	}
 
+	/**
+	 * @return string
+	 */
 	public function peekLongUTF() {
 		$pos = $this->pos;
 		$val = $this->readLongUTF();
@@ -470,13 +555,23 @@
 	}
 }
 
-class AMFReader {
+class AMFReader
+{
+	/**
+	* @var AMFStream
+	*/
 	public $stream;
 
-	public function __construct(&$stream) {
-		$this->stream =& $stream;
+	/**
+	 * @param AMFStream $stream
+	 */
+	public function __construct(AMFStream $stream) {
+		$this->stream = $stream;
 	}
 
+	/**
+	 * @return mixed
+	 */
 	public function readData() {
 		$value = null;
 
@@ -506,7 +601,6 @@
 			// null
 			case 6:
 				return null;
-				break;
 
 			// Mixed array
 			case 8:
@@ -547,23 +641,36 @@
 		return $value;
 	}
 
+	/**
+	 * @return float|false
+	 */
 	public function readDouble() {
 		return $this->stream->readDouble();
 	}
 
+	/**
+	 * @return bool
+	 */
 	public function readBoolean() {
 		return $this->stream->readByte() == 1;
 	}
 
+	/**
+	 * @return string
+	 */
 	public function readString() {
 		return $this->stream->readUTF();
 	}
 
+	/**
+	 * @return array
+	 */
 	public function readObject() {
 		// Get highest numerical index - ignored
 //		$highestIndex = $this->stream->readLong();
 
 		$data = array();
+		$key = null;
 
 		while ($key = $this->stream->readUTF()) {
 			$data[$key] = $this->readData();
@@ -576,15 +683,19 @@
 		return $data;
 	}
 
+	/**
+	 * @return array
+	 */
 	public function readMixedArray() {
 		// Get highest numerical index - ignored
 		$highestIndex = $this->stream->readLong();
 
 		$data = array();
+		$key = null;
 
 		while ($key = $this->stream->readUTF()) {
 			if (is_numeric($key)) {
-				$key = (float) $key;
+				$key = (int) $key;
 			}
 			$data[$key] = $this->readData();
 		}
@@ -597,6 +708,9 @@
 		return $data;
 	}
 
+	/**
+	 * @return array
+	 */
 	public function readArray() {
 		$length = $this->stream->readLong();
 		$data = array();
@@ -607,34 +721,61 @@
 		return $data;
 	}
 
+	/**
+	 * @return float|false
+	 */
 	public function readDate() {
 		$timestamp = $this->stream->readDouble();
 		$timezone = $this->stream->readInt();
 		return $timestamp;
 	}
 
+	/**
+	 * @return string
+	 */
 	public function readLongString() {
 		return $this->stream->readLongUTF();
 	}
 
+	/**
+	 * @return string
+	 */
 	public function readXML() {
 		return $this->stream->readLongUTF();
 	}
 
+	/**
+	 * @return array
+	 */
 	public function readTypedObject() {
 		$className = $this->stream->readUTF();
 		return $this->readObject();
 	}
 }
 
-class AVCSequenceParameterSetReader {
+class AVCSequenceParameterSetReader
+{
+	/**
+	 * @var string
+	 */
 	public $sps;
 	public $start = 0;
 	public $currentBytes = 0;
 	public $currentBits = 0;
+
+	/**
+	 * @var int
+	 */
 	public $width;
+
+	/**
+	 * @var int
+	 */
 	public $height;
 
+	/**
+	 * @param string $sps
+	 */
 	public function __construct($sps) {
 		$this->sps = $sps;
 	}
@@ -691,18 +832,29 @@
 		}
 	}
 
+	/**
+	 * @param int $bits
+	 */
 	public function skipBits($bits) {
 		$newBits = $this->currentBits + $bits;
 		$this->currentBytes += (int)floor($newBits / 8);
 		$this->currentBits = $newBits % 8;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function getBit() {
 		$result = (getid3_lib::BigEndian2Int(substr($this->sps, $this->currentBytes, 1)) >> (7 - $this->currentBits)) & 0x01;
 		$this->skipBits(1);
 		return $result;
 	}
 
+	/**
+	 * @param int $bits
+	 *
+	 * @return int
+	 */
 	public function getBits($bits) {
 		$result = 0;
 		for ($i = 0; $i < $bits; $i++) {
@@ -711,6 +863,9 @@
 		return $result;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function expGolombUe() {
 		$significantBits = 0;
 		$bit = $this->getBit();
@@ -726,6 +881,9 @@
 		return (1 << $significantBits) + $this->getBits($significantBits) - 1;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function expGolombSe() {
 		$result = $this->expGolombUe();
 		if (($result & 0x01) == 0) {
@@ -735,10 +893,16 @@
 		}
 	}
 
+	/**
+	 * @return int
+	 */
 	public function getWidth() {
 		return $this->width;
 	}
 
+	/**
+	 * @return int
+	 */
 	public function getHeight() {
 		return $this->height;
 	}