diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/ID3/getid3.lib.php --- a/wp/wp-includes/ID3/getid3.lib.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-includes/ID3/getid3.lib.php Tue Sep 27 16:37:53 2022 +0200 @@ -242,7 +242,7 @@ /** * ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic * - * @link http://www.psc.edu/general/software/packages/ieee/ieee.html + * @link https://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html * * @param string $byteword @@ -294,12 +294,12 @@ if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { // Not a Number - $floatvalue = false; + $floatvalue = NAN; } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { if ($signbit == '1') { - $floatvalue = '-infinity'; + $floatvalue = -INF; } else { - $floatvalue = '+infinity'; + $floatvalue = INF; } } elseif (($exponent == 0) && ($fraction == 0)) { if ($signbit == '1') { @@ -427,14 +427,20 @@ * @return string */ public static function Dec2Bin($number) { + if (!is_numeric($number)) { + // https://github.com/JamesHeinrich/getID3/issues/299 + trigger_error('TypeError: Dec2Bin(): Argument #1 ($number) must be numeric, '.gettype($number).' given', E_USER_WARNING); + return ''; + } + $bytes = array(); while ($number >= 256) { - $bytes[] = (($number / 256) - (floor($number / 256))) * 256; + $bytes[] = (int) (($number / 256) - (floor($number / 256))) * 256; $number = floor($number / 256); } - $bytes[] = $number; + $bytes[] = (int) $number; $binstring = ''; - for ($i = 0; $i < count($bytes); $i++) { - $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; + foreach ($bytes as $i => $byte) { + $binstring = (($i == count($bytes) - 1) ? decbin($byte) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring; } return $binstring; } @@ -665,6 +671,7 @@ // or // $foo['path']['to']['my'] = 'file.txt'; $ArrayPath = ltrim($ArrayPath, $Separator); + $ReturnedArray = array(); if (($pos = strpos($ArrayPath, $Separator)) !== false) { $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); } else { @@ -1538,12 +1545,21 @@ public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) { // Copy all entries from ['tags'] into common ['comments'] if (!empty($ThisFileInfo['tags'])) { - if (isset($ThisFileInfo['tags']['id3v1'])) { - // bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings - $ID3v1 = $ThisFileInfo['tags']['id3v1']; - unset($ThisFileInfo['tags']['id3v1']); - $ThisFileInfo['tags']['id3v1'] = $ID3v1; - unset($ID3v1); + + // Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1) + // and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets + // To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that + // the first entries in [comments] are the most correct and the "bad" ones (if any) come later. + // https://github.com/JamesHeinrich/getID3/issues/338 + $processLastTagTypes = array('id3v1','riff'); + foreach ($processLastTagTypes as $processLastTagType) { + if (isset($ThisFileInfo['tags'][$processLastTagType])) { + // bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings + $temp = $ThisFileInfo['tags'][$processLastTagType]; + unset($ThisFileInfo['tags'][$processLastTagType]); + $ThisFileInfo['tags'][$processLastTagType] = $temp; + unset($temp); + } } foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { foreach ($tagarray as $tagname => $tagdata) { @@ -1562,20 +1578,30 @@ // new value is identical but shorter-than (or equal-length to) one already in comments - skip break 2; } - } - if (function_exists('mb_convert_encoding')) { - if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) { - // value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1. - // As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character - break 2; + + if (function_exists('mb_convert_encoding')) { + if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) { + // value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1. + // As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character + break 2; + } } } } elseif (!is_array($value)) { - $newvaluelength = strlen(trim($value)); + $newvaluelength = strlen(trim($value)); + $newvaluelengthMB = mb_strlen(trim($value)); foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { - $oldvaluelength = strlen(trim($existingvalue)); + $oldvaluelength = strlen(trim($existingvalue)); + $oldvaluelengthMB = mb_strlen(trim($existingvalue)); + if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) { + // https://github.com/JamesHeinrich/getID3/issues/338 + // check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII) + // which will usually display unrepresentable characters as "?" + $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); + break; + } if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); break; @@ -1601,14 +1627,16 @@ } // attempt to standardize spelling of returned keys - $StandardizeFieldNames = array( - 'tracknumber' => 'track_number', - 'track' => 'track_number', - ); - foreach ($StandardizeFieldNames as $badkey => $goodkey) { - if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { - $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; - unset($ThisFileInfo['comments'][$badkey]); + if (!empty($ThisFileInfo['comments'])) { + $StandardizeFieldNames = array( + 'tracknumber' => 'track_number', + 'track' => 'track_number', + ); + foreach ($StandardizeFieldNames as $badkey => $goodkey) { + if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { + $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; + unset($ThisFileInfo['comments'][$badkey]); + } } } @@ -1734,6 +1762,7 @@ * @return float|bool */ public static function getFileSizeSyscall($path) { + $commandline = null; $filesize = false; if (GETID3_OS_ISWINDOWS) { @@ -1795,7 +1824,7 @@ * * @return string */ - public static function mb_basename($path, $suffix = null) { + public static function mb_basename($path, $suffix = '') { $splited = preg_split('#/#', rtrim($path, '/ ')); return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1); }