Skip to content

Commit

Permalink
External Libraries: Update getID3 to version 1.9.23.
Browse files Browse the repository at this point in the history
The latest version includes numerous bug fixes, a few new features, as well as various improvements for PHP 8.1 and PHP 8.2 support.

This commit also includes PHPCS adjustments previously made for a passing PHP Compatibility scan.

References:
* [https://github.com/JamesHeinrich/getID3/releases/tag/v1.9.23 getID3 1.9.23 release notes]
* [JamesHeinrich/getID3@v1.9.22...v1.9.23 Full list of changes in getID3 1.9.23]

Follow-up to [47601], [48278], [52254], [54376].

Props jrf.
Fixes #59683.

git-svn-id: https://develop.svn.wordpress.org/trunk@56975 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 20, 2023
1 parent 69a56e3 commit df57c55
Show file tree
Hide file tree
Showing 14 changed files with 195 additions and 120 deletions.
24 changes: 14 additions & 10 deletions src/wp-includes/ID3/getid3.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,32 @@ public static function intValueSupported($num) {
}
}
// if integers are 64-bit - no other check required
if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) { // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
return true;
}
return false;
}

/**
* Perform a division, guarding against division by zero
*
* @param float|int $numerator
* @param float|int $denominator
* @param float|int $fallback
* @return float|int
*/
public static function SafeDiv($numerator, $denominator, $fallback = 0) {
return $denominator ? $numerator / $denominator : $fallback;
}

/**
* @param string $fraction
*
* @return float
*/
public static function DecimalizeFraction($fraction) {
list($numerator, $denominator) = explode('/', $fraction);
return $numerator / ($denominator ? $denominator : 1);
return (int) $numerator / ($denominator ? $denominator : 1);
}

/**
Expand Down Expand Up @@ -871,10 +883,6 @@ public static function iconv_fallback_int_utf8($charval) {
* @return string
*/
public static function iconv_fallback_iso88591_utf8($string, $bom=false) {
if (function_exists('utf8_encode')) {
return utf8_encode($string);
}
// utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
$newcharstring = '';
if ($bom) {
$newcharstring .= "\xEF\xBB\xBF";
Expand Down Expand Up @@ -943,10 +951,6 @@ public static function iconv_fallback_iso88591_utf16($string) {
* @return string
*/
public static function iconv_fallback_utf8_iso88591($string) {
if (function_exists('utf8_decode')) {
return utf8_decode($string);
}
// utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
$newcharstring = '';
$offset = 0;
$stringlength = strlen($string);
Expand Down
32 changes: 26 additions & 6 deletions src/wp-includes/ID3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class getID3
*/
protected $startup_warning = '';

const VERSION = '1.9.22-202207161647';
const VERSION = '1.9.23-202310190849';
const FREAD_BUFFER_SIZE = 32768;

const ATTACHMENTS_NONE = false;
Expand Down Expand Up @@ -438,19 +438,19 @@ public function __construct() {
$this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n";
}

// check for magic quotes in PHP < 7.4.0 (when these functions became deprecated)
if (version_compare(PHP_VERSION, '7.4.0', '<')) {
// check for magic quotes in PHP < 5.4.0 (when these options were removed and getters always return false)
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
// Check for magic_quotes_runtime
if (function_exists('get_magic_quotes_runtime')) {
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
if (get_magic_quotes_runtime()) {
if (get_magic_quotes_runtime()) { // @phpstan-ignore-line
$this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n";
}
}
// Check for magic_quotes_gpc
if (function_exists('get_magic_quotes_gpc')) {
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_gpcDeprecated
if (get_magic_quotes_gpc()) {
if (get_magic_quotes_gpc()) { // @phpstan-ignore-line
$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";
}
}
Expand Down Expand Up @@ -1468,6 +1468,16 @@ public function GetFileFormatArray() {
'fail_ape' => 'ERROR',
),

// XZ - data - XZ compressed data
'7zip' => array(
'pattern' => '^7z\\xBC\\xAF\\x27\\x1C',
'group' => 'archive',
'module' => '7zip',
'mime_type' => 'application/x-7z-compressed',
'fail_id3' => 'ERROR',
'fail_ape' => 'ERROR',
),


// Misc other formats

Expand Down Expand Up @@ -1982,7 +1992,7 @@ public function CalculateCompressionRatioVideo() {
}
$BitrateUncompressed = $this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $FrameRate;

$this->info['video']['compression_ratio'] = $BitrateCompressed / $BitrateUncompressed;
$this->info['video']['compression_ratio'] = getid3_lib::SafeDiv($BitrateCompressed, $BitrateUncompressed, 1);
return true;
}

Expand Down Expand Up @@ -2188,6 +2198,8 @@ public function setStringMode($string) {
}

/**
* @phpstan-impure
*
* @return int|bool
*/
protected function ftell() {
Expand All @@ -2200,6 +2212,8 @@ protected function ftell() {
/**
* @param int $bytes
*
* @phpstan-impure
*
* @return string|false
*
* @throws getid3_exception
Expand Down Expand Up @@ -2245,6 +2259,8 @@ protected function fread($bytes) {
* @param int $bytes
* @param int $whence
*
* @phpstan-impure
*
* @return int
*
* @throws getid3_exception
Expand Down Expand Up @@ -2286,6 +2302,8 @@ protected function fseek($bytes, $whence=SEEK_SET) {
}

/**
* @phpstan-impure
*
* @return string|false
*
* @throws getid3_exception
Expand Down Expand Up @@ -2341,6 +2359,8 @@ protected function fgets() {
}

/**
* @phpstan-impure
*
* @return bool
*/
protected function feof() {
Expand Down
27 changes: 0 additions & 27 deletions src/wp-includes/ID3/license.commercial.txt

This file was deleted.

3 changes: 2 additions & 1 deletion src/wp-includes/ID3/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ GNU LGPL: https://gnu.org/licenses/lgpl.html (v3)

Mozilla MPL: https://www.mozilla.org/MPL/2.0/ (v2)

getID3 Commercial License: https://www.getid3.org/#gCL (payment required)
getID3 Commercial License: https://www.getid3.org/#gCL
(no longer available, existing licenses remain valid)

*****************************************************************
*****************************************************************
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/ID3/module.audio-video.asf.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function Analyze() {
$info['playtime_seconds'] = ($thisfile_asf_filepropertiesobject['play_duration'] / 10000000) - ($thisfile_asf_filepropertiesobject['preroll'] / 1000);

//$info['bitrate'] = $thisfile_asf_filepropertiesobject['max_bitrate'];
$info['bitrate'] = ((isset($thisfile_asf_filepropertiesobject['filesize']) ? $thisfile_asf_filepropertiesobject['filesize'] : $info['filesize']) * 8) / $info['playtime_seconds'];
$info['bitrate'] = getid3_lib::SafeDiv($thisfile_asf_filepropertiesobject['filesize'] * 8, $info['playtime_seconds']);
}
break;

Expand Down Expand Up @@ -1066,7 +1066,7 @@ public function Analyze() {
break;
}

if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { // @phpstan-ignore-line
foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
$thisfile_asf_audiomedia_currentstream['bitrate'] = $dataarray['bitrate'];
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public function Analyze() {
$videomediaoffset += 4;
$thisfile_asf_videomedia_currentstream['format_data']['codec_data'] = substr($streamdata['type_specific_data'], $videomediaoffset);

if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) {
if (!empty($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'])) { // @phpstan-ignore-line
foreach ($thisfile_asf['stream_bitrate_properties_object']['bitrate_records'] as $dummy => $dataarray) {
if (isset($dataarray['flags']['stream_number']) && ($dataarray['flags']['stream_number'] == $streamnumber)) {
$thisfile_asf_videomedia_currentstream['bitrate'] = $dataarray['bitrate'];
Expand Down
12 changes: 6 additions & 6 deletions src/wp-includes/ID3/module.audio-video.matroska.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ public function Analyze()
$track_info['display_x'] = (isset($trackarray['DisplayWidth']) ? $trackarray['DisplayWidth'] : $trackarray['PixelWidth']);
$track_info['display_y'] = (isset($trackarray['DisplayHeight']) ? $trackarray['DisplayHeight'] : $trackarray['PixelHeight']);

if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; }
if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; }
if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; }
if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; }
if (isset($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); }
if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }
if (isset($trackarray['PixelCropBottom'])) { $track_info['crop_bottom'] = $trackarray['PixelCropBottom']; }
if (isset($trackarray['PixelCropTop'])) { $track_info['crop_top'] = $trackarray['PixelCropTop']; }
if (isset($trackarray['PixelCropLeft'])) { $track_info['crop_left'] = $trackarray['PixelCropLeft']; }
if (isset($trackarray['PixelCropRight'])) { $track_info['crop_right'] = $trackarray['PixelCropRight']; }
if (!empty($trackarray['DefaultDuration'])) { $track_info['frame_rate'] = round(1000000000 / $trackarray['DefaultDuration'], 3); }
if (isset($trackarray['CodecName'])) { $track_info['codec'] = $trackarray['CodecName']; }

switch ($trackarray['CodecID']) {
case 'V_MS/VFW/FOURCC':
Expand Down

0 comments on commit df57c55

Please sign in to comment.