Skip to content

Commit e7d8965

Browse files
committed
External Libraries: Update getID3 to version 1.9.24.
In [60812], two changes related to PHP 8.5 compatibility were cherry picked from the upstream repository to be included in time for WordPress 6.9. Since then, a proper release has been tagged which includes several bug fixes in addition to the previous two changes. HEIF support has also been added to the Quicktime audio/video module. A full list of changes can be found on GitHub: https://github.com/JamesHeinrich/getID3/releases/tag/v1.9.24 Props TobiasBg. Fixes #64253. Built from https://develop.svn.wordpress.org/trunk@61253 git-svn-id: http://core.svn.wordpress.org/trunk@60565 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 10ce1b8 commit e7d8965

11 files changed

+269
-141
lines changed

wp-includes/ID3/getid3.lib.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// ///
1212
/////////////////////////////////////////////////////////////////
1313

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) {
1616
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT);
1717
} else {
1818
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING);
@@ -73,7 +73,8 @@ public static function trunc($floatnumber) {
7373

7474
/**
7575
* @param int|null $variable
76-
* @param int $increment
76+
* @param-out int $variable
77+
* @param int $increment
7778
*
7879
* @return bool
7980
*/
@@ -115,7 +116,9 @@ public static function intValueSupported($num) {
115116
// check if integers are 64-bit
116117
static $hasINT64 = null;
117118
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
119122
if (!$hasINT64 && !defined('PHP_INT_MIN')) {
120123
define('PHP_INT_MIN', ~PHP_INT_MAX);
121124
}
@@ -440,7 +443,7 @@ public static function BigEndian2String($number, $minbytes=1, $synchsafe=false,
440443
}
441444

442445
/**
443-
* @param int $number
446+
* @param int|string $number
444447
*
445448
* @return string
446449
*/
@@ -744,16 +747,36 @@ public static function array_min($arraydata, $returnkey=false) {
744747
* @return array|false
745748
*/
746749
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+
}
757780
}
758781
return false;
759782
}
@@ -1497,7 +1520,7 @@ public static function RGADamplitude2dB($amplitude) {
14971520
public static function GetDataImageSize($imgData, &$imageinfo=array()) {
14981521
if (PHP_VERSION_ID >= 50400) {
14991522
$GetDataImageSize = @getimagesizefromstring($imgData, $imageinfo);
1500-
if ($GetDataImageSize === false || !isset($GetDataImageSize[0], $GetDataImageSize[1])) {
1523+
if ($GetDataImageSize === false) {
15011524
return false;
15021525
}
15031526
$GetDataImageSize['height'] = $GetDataImageSize[0];
@@ -1525,7 +1548,7 @@ public static function GetDataImageSize($imgData, &$imageinfo=array()) {
15251548
fwrite($tmp, $imgData);
15261549
fclose($tmp);
15271550
$GetDataImageSize = @getimagesize($tempfilename, $imageinfo);
1528-
if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) {
1551+
if ($GetDataImageSize === false) {
15291552
return false;
15301553
}
15311554
$GetDataImageSize['height'] = $GetDataImageSize[0];
@@ -1719,7 +1742,7 @@ public static function EmbeddedLookup($key, $begin, $end, $file, $name) {
17191742
// METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
17201743
//$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
17211744
$explodedLine = explode("\t", $line, 2);
1722-
$ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
1745+
$ThisKey = $explodedLine[0];
17231746
$ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
17241747
$cache[$file][$name][$ThisKey] = trim($ThisValue);
17251748
}

wp-includes/ID3/getid3.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class getID3
387387
*/
388388
protected $startup_warning = '';
389389

390-
const VERSION = '1.9.23-202310190849';
390+
const VERSION = '1.9.24-202509040923';
391391
const FREAD_BUFFER_SIZE = 32768;
392392

393393
const ATTACHMENTS_NONE = false;
@@ -409,10 +409,10 @@ public function __construct() {
409409
$memoryLimit = ini_get('memory_limit');
410410
if (preg_match('#([0-9]+) ?M#i', $memoryLimit, $matches)) {
411411
// could be stored as "16M" rather than 16777216 for example
412-
$memoryLimit = $matches[1] * 1048576;
412+
$memoryLimit = (int) $matches[1] * 1048576;
413413
} elseif (preg_match('#([0-9]+) ?G#i', $memoryLimit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
414414
// could be stored as "2G" rather than 2147483648 for example
415-
$memoryLimit = $matches[1] * 1073741824;
415+
$memoryLimit = (int) $matches[1] * 1073741824;
416416
}
417417
$this->memory_limit = $memoryLimit;
418418

@@ -446,7 +446,7 @@ public function __construct() {
446446
}
447447
// Check for magic_quotes_gpc
448448
if (function_exists('get_magic_quotes_gpc')) {
449-
if (get_magic_quotes_gpc()) { // @phpstan-ignore-line
449+
if (get_magic_quotes_gpc()) {
450450
$this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n";
451451
}
452452
}
@@ -529,7 +529,7 @@ public function fread_buffer_size() {
529529
* @return bool
530530
*/
531531
public function setOption($optArray) {
532-
if (!is_array($optArray) || empty($optArray)) {
532+
if (empty($optArray)) {
533533
return false;
534534
}
535535
foreach ($optArray as $opt => $val) {
@@ -680,6 +680,8 @@ public function analyze($filename, $filesize=null, $original_filename='', $fp=nu
680680
catch (getid3_exception $e) {
681681
throw $e;
682682
}
683+
} else {
684+
$this->warning('skipping check for '.$tag_name.' tags since option_tag_'.$tag_name.'=FALSE');
683685
}
684686
}
685687
if (isset($this->info['id3v2']['tag_offset_start'])) {
@@ -1477,6 +1479,16 @@ public function GetFileFormatArray() {
14771479

14781480
// Misc other formats
14791481

1482+
// GPX - data - GPS Exchange Format
1483+
'gpx' => array (
1484+
'pattern' => '^<\\?xml [^>]+>[\s]*<gpx ',
1485+
'group' => 'misc',
1486+
'module' => 'gpx',
1487+
'mime_type' => 'application/gpx+xml',
1488+
'fail_id3' => 'ERROR',
1489+
'fail_ape' => 'ERROR',
1490+
),
1491+
14801492
// PAR2 - data - Parity Volume Set Specification 2.0
14811493
'par2' => array (
14821494
'pattern' => '^PAR2\\x00PKT',
@@ -1890,8 +1902,8 @@ public function ChannelsBitratePlaytimeCalculations() {
18901902

18911903
// Calculate combined bitrate - audio + video
18921904
$CombinedBitrate = 0;
1893-
$CombinedBitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0);
1894-
$CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
1905+
$CombinedBitrate += (isset($this->info['audio']['bitrate']) && ($this->info['audio']['bitrate'] != 'free') ? $this->info['audio']['bitrate'] : 0);
1906+
$CombinedBitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0);
18951907
if (($CombinedBitrate > 0) && empty($this->info['bitrate'])) {
18961908
$this->info['bitrate'] = $CombinedBitrate;
18971909
}
@@ -1998,7 +2010,9 @@ public function CalculateCompressionRatioAudio() {
19982010
if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) {
19992011
return false;
20002012
}
2001-
$this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
2013+
if ($this->info['audio']['bitrate'] != 'free') {
2014+
$this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
2015+
}
20022016

20032017
if (!empty($this->info['audio']['streams'])) {
20042018
foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {

0 commit comments

Comments
 (0)