wp/wp-includes/ID3/getid3.lib.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 // getid3.lib.php - part of getID3()                           //
     9 // getid3.lib.php - part of getID3()                           //
    10 //  see readme.txt for more details                            //
    10 //  see readme.txt for more details                            //
    11 //                                                            ///
    11 //                                                            ///
    12 /////////////////////////////////////////////////////////////////
    12 /////////////////////////////////////////////////////////////////
    13 
    13 
       
    14 if(!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) {
       
    15 	if(LIBXML_VERSION >= 20621) {
       
    16 		define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT);
       
    17 	} else {
       
    18 		define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING);
       
    19 	}
       
    20 }
    14 
    21 
    15 class getid3_lib
    22 class getid3_lib
    16 {
    23 {
    17 	/**
    24 	/**
    18 	 * @param string      $string
    25 	 * @param string      $string
   112 			if (!$hasINT64 && !defined('PHP_INT_MIN')) {
   119 			if (!$hasINT64 && !defined('PHP_INT_MIN')) {
   113 				define('PHP_INT_MIN', ~PHP_INT_MAX);
   120 				define('PHP_INT_MIN', ~PHP_INT_MAX);
   114 			}
   121 			}
   115 		}
   122 		}
   116 		// if integers are 64-bit - no other check required
   123 		// if integers are 64-bit - no other check required
   117 		if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
   124 		if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
   118 			return true;
   125 			return true;
   119 		}
   126 		}
   120 		return false;
   127 		return false;
       
   128 	}
       
   129 
       
   130 	/**
       
   131 	 * Perform a division, guarding against division by zero
       
   132 	 *
       
   133 	 * @param float|int $numerator
       
   134 	 * @param float|int $denominator
       
   135 	 * @param float|int $fallback
       
   136 	 * @return float|int
       
   137 	 */
       
   138 	public static function SafeDiv($numerator, $denominator, $fallback = 0) {
       
   139 		return $denominator ? $numerator / $denominator : $fallback;
   121 	}
   140 	}
   122 
   141 
   123 	/**
   142 	/**
   124 	 * @param string $fraction
   143 	 * @param string $fraction
   125 	 *
   144 	 *
   126 	 * @return float
   145 	 * @return float
   127 	 */
   146 	 */
   128 	public static function DecimalizeFraction($fraction) {
   147 	public static function DecimalizeFraction($fraction) {
   129 		list($numerator, $denominator) = explode('/', $fraction);
   148 		list($numerator, $denominator) = explode('/', $fraction);
   130 		return $numerator / ($denominator ? $denominator : 1);
   149 		return (int) $numerator / ($denominator ? $denominator : 1);
   131 	}
   150 	}
   132 
   151 
   133 	/**
   152 	/**
   134 	 * @param string $binarynumerator
   153 	 * @param string $binarynumerator
   135 	 *
   154 	 *
   301 			} else {
   320 			} else {
   302 				$floatvalue = INF;
   321 				$floatvalue = INF;
   303 			}
   322 			}
   304 		} elseif (($exponent == 0) && ($fraction == 0)) {
   323 		} elseif (($exponent == 0) && ($fraction == 0)) {
   305 			if ($signbit == '1') {
   324 			if ($signbit == '1') {
   306 				$floatvalue = -0;
   325 				$floatvalue = -0.0;
   307 			} else {
   326 			} else {
   308 				$floatvalue = 0;
   327 				$floatvalue = 0.0;
   309 			}
   328 			}
   310 			$floatvalue = ($signbit ? 0 : -0);
       
   311 		} elseif (($exponent == 0) && ($fraction != 0)) {
   329 		} elseif (($exponent == 0) && ($fraction != 0)) {
   312 			// These are 'unnormalized' values
   330 			// These are 'unnormalized' values
   313 			$floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring);
   331 			$floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring);
   314 			if ($signbit == '1') {
   332 			if ($signbit == '1') {
   315 				$floatvalue *= -1;
   333 				$floatvalue *= -1;
   730 			// http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html
   748 			// http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html
   731 			// https://core.trac.wordpress.org/changeset/29378
   749 			// https://core.trac.wordpress.org/changeset/29378
   732 			// This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is
   750 			// This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is
   733 			// disabled by default, but is still needed when LIBXML_NOENT is used.
   751 			// disabled by default, but is still needed when LIBXML_NOENT is used.
   734 			$loader = @libxml_disable_entity_loader(true);
   752 			$loader = @libxml_disable_entity_loader(true);
   735 			$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', LIBXML_NOENT);
   753 			$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS);
   736 			$return = self::SimpleXMLelement2array($XMLobject);
   754 			$return = self::SimpleXMLelement2array($XMLobject);
   737 			@libxml_disable_entity_loader($loader);
   755 			@libxml_disable_entity_loader($loader);
   738 			return $return;
   756 			return $return;
   739 		}
   757 		}
   740 		return false;
   758 		return false;
   863 	 * @param bool   $bom
   881 	 * @param bool   $bom
   864 	 *
   882 	 *
   865 	 * @return string
   883 	 * @return string
   866 	 */
   884 	 */
   867 	public static function iconv_fallback_iso88591_utf8($string, $bom=false) {
   885 	public static function iconv_fallback_iso88591_utf8($string, $bom=false) {
   868 		if (function_exists('utf8_encode')) {
       
   869 			return utf8_encode($string);
       
   870 		}
       
   871 		// utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
       
   872 		$newcharstring = '';
   886 		$newcharstring = '';
   873 		if ($bom) {
   887 		if ($bom) {
   874 			$newcharstring .= "\xEF\xBB\xBF";
   888 			$newcharstring .= "\xEF\xBB\xBF";
   875 		}
   889 		}
   876 		for ($i = 0; $i < strlen($string); $i++) {
   890 		for ($i = 0; $i < strlen($string); $i++) {
   935 	 * @param string $string
   949 	 * @param string $string
   936 	 *
   950 	 *
   937 	 * @return string
   951 	 * @return string
   938 	 */
   952 	 */
   939 	public static function iconv_fallback_utf8_iso88591($string) {
   953 	public static function iconv_fallback_utf8_iso88591($string) {
   940 		if (function_exists('utf8_decode')) {
       
   941 			return utf8_decode($string);
       
   942 		}
       
   943 		// utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
       
   944 		$newcharstring = '';
   954 		$newcharstring = '';
   945 		$offset = 0;
   955 		$offset = 0;
   946 		$stringlength = strlen($string);
   956 		$stringlength = strlen($string);
   947 		while ($offset < $stringlength) {
   957 		while ($offset < $stringlength) {
   948 			if ((ord($string[$offset]) | 0x07) == 0xF7) {
   958 			if ((ord($string[$offset]) | 0x07) == 0xF7) {