Make WordPress Core


Ignore:
Timestamp:
07/31/2017 07:49:31 PM (9 years ago)
Author:
wonderboymusic
Message:

Media: update the getID3 library to version 1.9.14 to avoid fatal errors in PHP7.

Props MyThemeShop for the initial patch.
Fixes #41496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/module.audio.mp3.php

    r32979 r41196  
    3535                if (!$this->getOnlyMPEGaudioInfo($info['avdataoffset'])) {
    3636                        if ($this->allow_bruteforce) {
    37                                 $info['error'][] = 'Rescanning file in BruteForce mode';
     37                                $this->error('Rescanning file in BruteForce mode');
    3838                                $this->getOnlyMPEGaudioInfoBruteForce($this->getid3->fp, $info);
    3939                        }
     
    7373
    7474                        }
    75                         $info['warning'][] = $synchoffsetwarning;
     75                        $this->warning($synchoffsetwarning);
    7676
    7777                }
     
    135135
    136136                                default:
    137                                         $info['warning'][] = 'Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"';
     137                                        $this->warning('Expecting [audio][dataformat] to be mp1/mp2/mp3 when fileformat == mp3, [audio][dataformat] actually "'.$info['audio']['dataformat'].'"');
    138138                                        break;
    139139                        }
     
    425425
    426426                if ($this->fseek($offset) != 0) {
    427                         $info['error'][] = 'decodeMPEGaudioHeader() failed to seek to next offset at '.$offset;
     427                        $this->error('decodeMPEGaudioHeader() failed to seek to next offset at '.$offset);
    428428                        return false;
    429429                }
     
    438438
    439439                $head4 = substr($headerstring, 0, 4);
    440 
     440                $head4_key = getid3_lib::PrintHexBytes($head4, true, false, false);
    441441                static $MPEGaudioHeaderDecodeCache = array();
    442                 if (isset($MPEGaudioHeaderDecodeCache[$head4])) {
    443                         $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4];
     442                if (isset($MPEGaudioHeaderDecodeCache[$head4_key])) {
     443                        $MPEGheaderRawArray = $MPEGaudioHeaderDecodeCache[$head4_key];
    444444                } else {
    445445                        $MPEGheaderRawArray = self::MPEGaudioHeaderDecode($head4);
    446                         $MPEGaudioHeaderDecodeCache[$head4] = $MPEGheaderRawArray;
     446                        $MPEGaudioHeaderDecodeCache[$head4_key] = $MPEGheaderRawArray;
    447447                }
    448448
    449449                static $MPEGaudioHeaderValidCache = array();
    450                 if (!isset($MPEGaudioHeaderValidCache[$head4])) { // Not in cache
    451                         //$MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true);  // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
    452                         $MPEGaudioHeaderValidCache[$head4] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
     450                if (!isset($MPEGaudioHeaderValidCache[$head4_key])) { // Not in cache
     451                        //$MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, true);  // allow badly-formatted freeformat (from LAME 3.90 - 3.93.1)
     452                        $MPEGaudioHeaderValidCache[$head4_key] = self::MPEGaudioHeaderValid($MPEGheaderRawArray, false, false);
    453453                }
    454454
     
    460460
    461461
    462                 if ($MPEGaudioHeaderValidCache[$head4]) {
     462                if ($MPEGaudioHeaderValidCache[$head4_key]) {
    463463                        $thisfile_mpeg_audio['raw'] = $MPEGheaderRawArray;
    464464                } else {
    465                         $info['error'][] = 'Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset;
     465                        $this->error('Invalid MPEG audio header ('.getid3_lib::PrintHexBytes($head4).') at offset '.$offset);
    466466                        return false;
    467467                }
     
    491491                if ($thisfile_mpeg_audio['raw']['bitrate'] == 15) {
    492492                        // http://www.hydrogenaudio.org/?act=ST&f=16&t=9682&st=0
    493                         $info['warning'][] = 'Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1';
     493                        $this->warning('Invalid bitrate index (15), this is a known bug in free-format MP3s encoded by LAME v3.90 - 3.93.1');
    494494                        $thisfile_mpeg_audio['raw']['bitrate'] = 0;
    495495                }
     
    513513                                                // these are ok
    514514                                        } else {
    515                                                 $info['error'][] = $thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
     515                                                $this->error($thisfile_mpeg_audio['bitrate'].'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.');
    516516                                                return false;
    517517                                        }
     
    524524                                                // these are ok
    525525                                        } else {
    526                                                 $info['error'][] = intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.';
     526                                                $this->error(intval(round($thisfile_mpeg_audio['bitrate'] / 1000)).'kbps not allowed in Layer 2, '.$thisfile_mpeg_audio['channelmode'].'.');
    527527                                                return false;
    528528                                        }
     
    546546                                $nextframetestoffset = $offset + $thisfile_mpeg_audio['framelength'];
    547547                        } else {
    548                                 $info['error'][] = 'Frame at offset('.$offset.') is has an invalid frame length.';
     548                                $this->error('Frame at offset('.$offset.') is has an invalid frame length.');
    549549                                return false;
    550550                        }
     
    649649
    650650                                //if (($thisfile_mpeg_audio['bitrate'] == 'free') && !empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
    651                                 if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
    652 
    653                                         $framelengthfloat = $thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames'];
     651                                //if (!empty($thisfile_mpeg_audio['VBR_frames']) && !empty($thisfile_mpeg_audio['VBR_bytes'])) {
     652                                if (!empty($thisfile_mpeg_audio['VBR_frames'])) {
     653                                        $used_filesize  = 0;
     654                                        if (!empty($thisfile_mpeg_audio['VBR_bytes'])) {
     655                                                $used_filesize = $thisfile_mpeg_audio['VBR_bytes'];
     656                                        } elseif (!empty($info['filesize'])) {
     657                                                $used_filesize  = $info['filesize'];
     658                                                $used_filesize -= intval(@$info['id3v2']['headerlength']);
     659                                                $used_filesize -= (isset($info['id3v1']) ? 128 : 0);
     660                                                $used_filesize -= (isset($info['tag_offset_end']) ? $info['tag_offset_end'] - $info['tag_offset_start'] : 0);
     661                                                $this->warning('MP3.Xing header missing VBR_bytes, assuming MPEG audio portion of file is '.number_format($used_filesize).' bytes');
     662                                        }
     663
     664                                        $framelengthfloat = $used_filesize / $thisfile_mpeg_audio['VBR_frames'];
    654665
    655666                                        if ($thisfile_mpeg_audio['layer'] == '1') {
     
    838849                                                $thisfile_mpeg_audio_lame['preset_used']       = self::LAMEpresetUsedLookup($thisfile_mpeg_audio_lame);
    839850                                                if (!empty($thisfile_mpeg_audio_lame['preset_used_id']) && empty($thisfile_mpeg_audio_lame['preset_used'])) {
    840                                                         $info['warning'][] = 'Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org';
     851                                                        $this->warning('Unknown LAME preset used ('.$thisfile_mpeg_audio_lame['preset_used_id'].') - please report to info@getid3.org');
    841852                                                }
    842853                                                if (($thisfile_mpeg_audio_lame['short_version'] == 'LAME3.90.') && !empty($thisfile_mpeg_audio_lame['preset_used_id'])) {
     
    882893                                        }
    883894                                        if ($thisfile_mpeg_audio['bitrate_mode'] == 'vbr') {
    884                                                 $info['warning'][] = 'VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.';
     895                                                $this->warning('VBR file with no VBR header. Bitrate values calculated from actual frame bitrates.');
    885896                                        }
    886897                                }
     
    909920                                //      if ($PossibleNullByte === "\x00") {
    910921                                                $info['avdataend']--;
    911                                 //              $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
     922                                //              $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored');
    912923                                //      } else {
    913                                 //              $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
     924                                //              $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)');
    914925                                //      }
    915926                                } else {
    916                                         $info['warning'][] = 'Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)';
     927                                        $this->warning('Too much data in file: expecting '.$ExpectedNumberOfAudioBytes.' bytes of audio data, found '.($info['avdataend'] - $info['avdataoffset']).' ('.(($info['avdataend'] - $info['avdataoffset']) - $ExpectedNumberOfAudioBytes).' bytes too many)');
    917928                                }
    918929                        }
     
    932943                                        }
    933944                                } else {
    934                                         $info['error'][] = 'Error calculating frame length of free-format MP3 without Xing/LAME header';
     945                                        $this->error('Error calculating frame length of free-format MP3 without Xing/LAME header');
    935946                                }
    936947                        }
     
    949960                                        $thisfile_mpeg_audio['VBR_bitrate'] = (isset($thisfile_mpeg_audio['VBR_bytes']) ? (($thisfile_mpeg_audio['VBR_bytes'] / $thisfile_mpeg_audio['VBR_frames']) * 8) * ($info['audio']['sample_rate'] / $bytes_per_frame) : 0);
    950961                                        if ($thisfile_mpeg_audio['VBR_bitrate'] > 0) {
    951                                                 $info['audio']['bitrate']         = $thisfile_mpeg_audio['VBR_bitrate'];
     962                                                $info['audio']['bitrate']       = $thisfile_mpeg_audio['VBR_bitrate'];
    952963                                                $thisfile_mpeg_audio['bitrate'] = $thisfile_mpeg_audio['VBR_bitrate']; // to avoid confusion
    953964                                        }
     
    10751086        public function RecursiveFrameScanning(&$offset, &$nextframetestoffset, $ScanAsCBR) {
    10761087                $info = &$this->getid3->info;
    1077                 $firstframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
     1088                $firstframetestarray = array('error' => array(), 'warning'=> array(), 'avdataend' => $info['avdataend'], 'avdataoffset' => $info['avdataoffset']);
    10781089                $this->decodeMPEGaudioHeader($offset, $firstframetestarray, false);
    10791090
     
    10851096                        }
    10861097
    1087                         $nextframetestarray = array('error'=>'', 'warning'=>'', 'avdataend'=>$info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
     1098                        $nextframetestarray = array('error' => array(), 'warning' => array(), 'avdataend' => $info['avdataend'], 'avdataoffset'=>$info['avdataoffset']);
    10881099                        if ($this->decodeMPEGaudioHeader($nextframetestoffset, $nextframetestarray, false)) {
    10891100                                if ($ScanAsCBR) {
     
    10991110                                        $nextframetestoffset += $nextframetestarray['mpeg']['audio']['framelength'];
    11001111                                } else {
    1101                                         $info['error'][] = 'Frame at offset ('.$offset.') is has an invalid frame length.';
     1112                                        $this->error('Frame at offset ('.$offset.') is has an invalid frame length.');
    11021113                                        return false;
    11031114                                }
     
    11111122
    11121123                                // next frame is not valid, note the error and fail, so scanning can contiue for a valid frame sequence
    1113                                 $info['warning'][] = 'Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.';
     1124                                $this->warning('Frame at offset ('.$offset.') is valid, but the next one at ('.$nextframetestoffset.') is not.');
    11141125
    11151126                                return false;
     
    11541165                        }
    11551166                        if (!$framelength) {
    1156                                 $info['error'][] = 'Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset;
     1167                                $this->error('Cannot find next free-format synch pattern ('.getid3_lib::PrintHexBytes($SyncPattern1).' or '.getid3_lib::PrintHexBytes($SyncPattern2).') after offset '.$offset);
    11571168                                return false;
    11581169                        } else {
    1159                                 $info['warning'][] = 'ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)';
     1170                                $this->warning('ModeExtension varies between first frame and other frames (known free-format issue in LAME 3.88)');
    11601171                                $info['audio']['codec']   = 'LAME';
    11611172                                $info['audio']['encoder'] = 'LAME3.88';
     
    11841195                                        $nextoffset++;
    11851196                                } else {
    1186                                         $info['error'][] = 'Did not find expected free-format sync pattern at offset '.$nextoffset;
     1197                                        $this->error('Did not find expected free-format sync pattern at offset '.$nextoffset);
    11871198                                        return false;
    11881199                                }
     
    12821293                                                        if ($max_frames_scan && (++$frames_scanned >= $max_frames_scan)) {
    12831294                                                                $pct_data_scanned = ($this->ftell() - $info['avdataoffset']) / ($info['avdataend'] - $info['avdataoffset']);
    1284                                                                 $info['warning'][] = 'too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
     1295                                                                $this->warning('too many MPEG audio frames to scan, only scanned first '.$max_frames_scan.' frames ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.');
    12851296                                                                foreach ($Distribution as $key1 => $value1) {
    12861297                                                                        foreach ($value1 as $key2 => $value2) {
     
    13091320                $info['mpeg']['audio']['padding_distribution']   = $Distribution['padding'];
    13101321                if (count($Distribution['version']) > 1) {
    1311                         $info['error'][] = 'Corrupt file - more than one MPEG version detected';
     1322                        $this->error('Corrupt file - more than one MPEG version detected');
    13121323                }
    13131324                if (count($Distribution['layer']) > 1) {
    1314                         $info['error'][] = 'Corrupt file - more than one MPEG layer detected';
     1325                        $this->error('Corrupt file - more than one MPEG layer detected');
    13151326                }
    13161327                if (count($Distribution['frequency']) > 1) {
    1317                         $info['error'][] = 'Corrupt file - more than one MPEG sample rate detected';
     1328                        $this->error('Corrupt file - more than one MPEG sample rate detected');
    13181329                }
    13191330
     
    13271338                $info['mpeg']['audio']['frame_count']  = array_sum($Distribution['bitrate']);
    13281339                if ($info['mpeg']['audio']['frame_count'] == 0) {
    1329                         $info['error'][] = 'no MPEG audio frames found';
     1340                        $this->error('no MPEG audio frames found');
    13301341                        return false;
    13311342                }
     
    13621373                $sync_seek_buffer_size = min(128 * 1024, $info['avdataend'] - $avdataoffset);
    13631374                if ($sync_seek_buffer_size <= 0) {
    1364                         $info['error'][] = 'Invalid $sync_seek_buffer_size at offset '.$avdataoffset;
     1375                        $this->error('Invalid $sync_seek_buffer_size at offset '.$avdataoffset);
    13651376                        return false;
    13661377                }
     
    13731384                                if ($SynchSeekOffset > $sync_seek_buffer_size) {
    13741385                                        // if a synch's not found within the first 128k bytes, then give up
    1375                                         $info['error'][] = 'Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB';
     1386                                        $this->error('Could not find valid MPEG audio synch within the first '.round($sync_seek_buffer_size / 1024).'kB');
    13761387                                        if (isset($info['audio']['bitrate'])) {
    13771388                                                unset($info['audio']['bitrate']);
     
    13871398                                } elseif (feof($this->getid3->fp)) {
    13881399
    1389                                         $info['error'][] = 'Could not find valid MPEG audio synch before end of file';
     1400                                        $this->error('Could not find valid MPEG audio synch before end of file');
    13901401                                        if (isset($info['audio']['bitrate'])) {
    13911402                                                unset($info['audio']['bitrate']);
     
    14021413
    14031414                        if (($SynchSeekOffset + 1) >= strlen($header)) {
    1404                                 $info['error'][] = 'Could not find valid MPEG synch before end of file';
     1415                                $this->error('Could not find valid MPEG synch before end of file');
    14051416                                return false;
    14061417                        }
     
    14451456                                                                $info = $dummy;
    14461457                                                                $info['avdataoffset'] = $GarbageOffsetEnd;
    1447                                                                 $info['warning'][] = 'apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd;
     1458                                                                $this->warning('apparently-valid VBR header not used because could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.'), but did find valid CBR stream starting at '.$GarbageOffsetEnd);
    14481459                                                        } else {
    1449                                                                 $info['warning'][] = 'using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')';
     1460                                                                $this->warning('using data from VBR header even though could not find '.GETID3_MP3_VALID_CHECK_FRAMES.' consecutive MPEG-audio frames immediately after VBR header (garbage data for '.($GarbageOffsetEnd - $GarbageOffsetStart).' bytes between '.$GarbageOffsetStart.' and '.$GarbageOffsetEnd.')');
    14501461                                                        }
    14511462                                                }
     
    15401551                                                }
    15411552                                                if ($pct_data_scanned > 0) {
    1542                                                         $info['warning'][] = 'too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.';
     1553                                                        $this->warning('too many MPEG audio frames to scan, only scanned '.$frames_scanned.' frames in '.$max_scan_segments.' segments ('.number_format($pct_data_scanned * 100, 1).'% of file) and extrapolated distribution, playtime and bitrate may be incorrect.');
    15431554                                                        foreach ($info['mpeg']['audio'] as $key1 => $value1) {
    15441555                                                                if (!preg_match('#_distribution$#i', $key1)) {
     
    15521563
    15531564                                                if ($SynchErrorsFound > 0) {
    1554                                                         $info['warning'][] = 'Found '.$SynchErrorsFound.' synch errors in histogram analysis';
     1565                                                        $this->warning('Found '.$SynchErrorsFound.' synch errors in histogram analysis');
    15551566                                                        //return false;
    15561567                                                }
     
    15651576                                                }
    15661577                                                if ($framecounter == 0) {
    1567                                                         $info['error'][] = 'Corrupt MP3 file: framecounter == zero';
     1578                                                        $this->error('Corrupt MP3 file: framecounter == zero');
    15681579                                                        return false;
    15691580                                                }
     
    16001611                                if (empty($info['mpeg']['audio'])) {
    16011612
    1602                                         $info['error'][] = 'could not find valid MPEG synch before end of file';
     1613                                        $this->error('could not find valid MPEG synch before end of file');
    16031614                                        if (isset($info['audio']['bitrate'])) {
    16041615                                                unset($info['audio']['bitrate']);
Note: See TracChangeset for help on using the changeset viewer.