|
11 | 11 | // /// |
12 | 12 | ///////////////////////////////////////////////////////////////// |
13 | 13 |
|
14 | | -if(!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) { |
15 | | - if(LIBXML_VERSION >= 20621) { |
| 14 | +if (!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) { |
| 15 | + if (LIBXML_VERSION >= 20621) { |
16 | 16 | define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT); |
17 | 17 | } else { |
18 | 18 | define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING); |
@@ -73,7 +73,8 @@ public static function trunc($floatnumber) { |
73 | 73 |
|
74 | 74 | /** |
75 | 75 | * @param int|null $variable |
76 | | - * @param int $increment |
| 76 | + * @param-out int $variable |
| 77 | + * @param int $increment |
77 | 78 | * |
78 | 79 | * @return bool |
79 | 80 | */ |
@@ -115,7 +116,9 @@ public static function intValueSupported($num) { |
115 | 116 | // check if integers are 64-bit |
116 | 117 | static $hasINT64 = null; |
117 | 118 | if ($hasINT64 === null) { // 10x faster than is_null() |
118 | | - $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1 |
| 119 | + /** @var int|float|object $bigInt */ |
| 120 | + $bigInt = pow(2, 31); |
| 121 | + $hasINT64 = is_int($bigInt); // 32-bit int are limited to (2^31)-1 |
119 | 122 | if (!$hasINT64 && !defined('PHP_INT_MIN')) { |
120 | 123 | define('PHP_INT_MIN', ~PHP_INT_MAX); |
121 | 124 | } |
@@ -440,7 +443,7 @@ public static function BigEndian2String($number, $minbytes=1, $synchsafe=false, |
440 | 443 | } |
441 | 444 |
|
442 | 445 | /** |
443 | | - * @param int $number |
| 446 | + * @param int|string $number |
444 | 447 | * |
445 | 448 | * @return string |
446 | 449 | */ |
@@ -744,16 +747,36 @@ public static function array_min($arraydata, $returnkey=false) { |
744 | 747 | * @return array|false |
745 | 748 | */ |
746 | 749 | public static function XML2array($XMLstring) { |
747 | | - if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) { |
748 | | - // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html |
749 | | - // https://core.trac.wordpress.org/changeset/29378 |
750 | | - // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is |
751 | | - // disabled by default, but is still needed when LIBXML_NOENT is used. |
752 | | - $loader = @libxml_disable_entity_loader(true); |
753 | | - $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS); |
754 | | - $return = self::SimpleXMLelement2array($XMLobject); |
755 | | - @libxml_disable_entity_loader($loader); |
756 | | - return $return; |
| 750 | + if (function_exists('simplexml_load_string')) { |
| 751 | + if (PHP_VERSION_ID < 80000) { |
| 752 | + if (function_exists('libxml_disable_entity_loader')) { |
| 753 | + // http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html |
| 754 | + // https://core.trac.wordpress.org/changeset/29378 |
| 755 | + // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is |
| 756 | + // disabled by default, but is still needed when LIBXML_NOENT is used. |
| 757 | + $loader = @libxml_disable_entity_loader(true); |
| 758 | + $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS); |
| 759 | + $return = self::SimpleXMLelement2array($XMLobject); |
| 760 | + @libxml_disable_entity_loader($loader); |
| 761 | + return $return; |
| 762 | + } |
| 763 | + } else { |
| 764 | + $allow = false; |
| 765 | + if (defined('LIBXML_VERSION') && (LIBXML_VERSION >= 20900)) { |
| 766 | + // https://www.php.net/manual/en/function.libxml-disable-entity-loader.php |
| 767 | + // "as of libxml 2.9.0 entity substitution is disabled by default, so there is no need to disable the loading |
| 768 | + // of external entities, unless there is the need to resolve internal entity references with LIBXML_NOENT." |
| 769 | + $allow = true; |
| 770 | + } elseif (function_exists('libxml_set_external_entity_loader')) { |
| 771 | + libxml_set_external_entity_loader(function () { return null; }); // https://www.zend.com/blog/cve-2023-3823 |
| 772 | + $allow = true; |
| 773 | + } |
| 774 | + if ($allow) { |
| 775 | + $XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS); |
| 776 | + $return = self::SimpleXMLelement2array($XMLobject); |
| 777 | + return $return; |
| 778 | + } |
| 779 | + } |
757 | 780 | } |
758 | 781 | return false; |
759 | 782 | } |
@@ -1497,7 +1520,7 @@ public static function RGADamplitude2dB($amplitude) { |
1497 | 1520 | public static function GetDataImageSize($imgData, &$imageinfo=array()) { |
1498 | 1521 | if (PHP_VERSION_ID >= 50400) { |
1499 | 1522 | $GetDataImageSize = @getimagesizefromstring($imgData, $imageinfo); |
1500 | | - if ($GetDataImageSize === false || !isset($GetDataImageSize[0], $GetDataImageSize[1])) { |
| 1523 | + if ($GetDataImageSize === false) { |
1501 | 1524 | return false; |
1502 | 1525 | } |
1503 | 1526 | $GetDataImageSize['height'] = $GetDataImageSize[0]; |
@@ -1525,7 +1548,7 @@ public static function GetDataImageSize($imgData, &$imageinfo=array()) { |
1525 | 1548 | fwrite($tmp, $imgData); |
1526 | 1549 | fclose($tmp); |
1527 | 1550 | $GetDataImageSize = @getimagesize($tempfilename, $imageinfo); |
1528 | | - if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) { |
| 1551 | + if ($GetDataImageSize === false) { |
1529 | 1552 | return false; |
1530 | 1553 | } |
1531 | 1554 | $GetDataImageSize['height'] = $GetDataImageSize[0]; |
@@ -1719,7 +1742,7 @@ public static function EmbeddedLookup($key, $begin, $end, $file, $name) { |
1719 | 1742 | // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key |
1720 | 1743 | //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1)); |
1721 | 1744 | $explodedLine = explode("\t", $line, 2); |
1722 | | - $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : ''); |
| 1745 | + $ThisKey = $explodedLine[0]; |
1723 | 1746 | $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : ''); |
1724 | 1747 | $cache[$file][$name][$ThisKey] = trim($ThisValue); |
1725 | 1748 | } |
|
0 commit comments