Make WordPress Core


Ignore:
Timestamp:
07/31/2017 07:49:31 PM (7 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-video.riff.php

    r29734 r41196  
    191191                    $thisfile_audio['wformattag'] = $thisfile_riff_audio[$streamindex]['raw']['wFormatTag'];
    192192                    if (!isset($thisfile_riff_audio[$streamindex]['bitrate']) || ($thisfile_riff_audio[$streamindex]['bitrate'] == 0)) {
    193                         $info['error'][] = 'Corrupt RIFF file: bitrate_audio == zero';
     193                        $this->error('Corrupt RIFF file: bitrate_audio == zero');
    194194                        return false;
    195195                    }
     
    200200                    $thisfile_audio = getid3_lib::array_merge_noclobber($thisfile_audio, $thisfile_riff_audio[$streamindex]);
    201201                    if (substr($thisfile_audio['codec'], 0, strlen('unknown: 0x')) == 'unknown: 0x') {
    202                         $info['warning'][] = 'Audio codec = '.$thisfile_audio['codec'];
     202                        $this->warning('Audio codec = '.$thisfile_audio['codec']);
    203203                    }
    204204                    $thisfile_audio['bitrate'] = $thisfile_riff_audio[$streamindex]['bitrate'];
     
    303303                            $thisfile_riff_WAVE_bext_0['origin_date_unix'] = gmmktime($bext_timestamp['hour'], $bext_timestamp['minute'], $bext_timestamp['second'], $bext_timestamp['month'], $bext_timestamp['day'], $bext_timestamp['year']);
    304304                        } else {
    305                             $info['warning'][] = 'RIFF.WAVE.BEXT.origin_time is invalid';
     305                            $this->warning('RIFF.WAVE.BEXT.origin_time is invalid');
    306306                        }
    307307                    } else {
    308                         $info['warning'][] = 'RIFF.WAVE.BEXT.origin_date is invalid';
     308                        $this->warning('RIFF.WAVE.BEXT.origin_date is invalid');
    309309                    }
    310310                    $thisfile_riff['comments']['author'][] = $thisfile_riff_WAVE_bext_0['author'];
     
    386386
    387387                        if ($SNDM_thisTagSize != (4 + 4 + 2 + 2 + $SNDM_thisTagDataSize)) {
    388                             $info['warning'][] = 'RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
     388                            $this->warning('RIFF.WAVE.SNDM.data contains tag not expected length (expected: '.$SNDM_thisTagSize.', found: '.(4 + 4 + 2 + 2 + $SNDM_thisTagDataSize).') at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
    389389                            break;
    390390                        } elseif ($SNDM_thisTagSize <= 0) {
    391                             $info['warning'][] = 'RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
     391                            $this->warning('RIFF.WAVE.SNDM.data contains zero-size tag at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
    392392                            break;
    393393                        }
     
    398398                            $thisfile_riff_WAVE_SNDM_0['parsed'][$parsedkey] = $SNDM_thisTagDataText;
    399399                        } else {
    400                             $info['warning'][] = 'RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')';
     400                            $this->warning('RIFF.WAVE.SNDM contains unknown tag "'.$SNDM_thisTagKey.'" at offset '.$SNDM_startoffset.' (file offset '.($thisfile_riff_WAVE_SNDM_0['offset'] + $SNDM_startoffset).')');
    401401                        }
    402402                    }
     
    429429                        if (isset($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO']) && !empty($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) && !empty($thisfile_riff_WAVE['iXML'][0]['timecode_rate'])) {
    430430                            $samples_since_midnight = floatval(ltrim($parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_HI'].$parsedXML['SPEED']['TIMESTAMP_SAMPLES_SINCE_MIDNIGHT_LO'], '0'));
    431                             $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE'];
     431                            $timestamp_sample_rate = (is_array($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) ? max($parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']) : $parsedXML['SPEED']['TIMESTAMP_SAMPLE_RATE']); // XML could possibly contain more than one TIMESTAMP_SAMPLE_RATE tag, returning as array instead of integer [why? does it make sense? perhaps doesn't matter but getID3 needs to deal with it] - see https://github.com/JamesHeinrich/getID3/issues/105
     432                            $thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] = $samples_since_midnight / $timestamp_sample_rate;
    432433                            $h = floor( $thisfile_riff_WAVE['iXML'][0]['timecode_seconds']       / 3600);
    433434                            $m = floor(($thisfile_riff_WAVE['iXML'][0]['timecode_seconds'] - ($h * 3600))      / 60);
     
    436437                            $thisfile_riff_WAVE['iXML'][0]['timecode_string']       = sprintf('%02d:%02d:%02d:%05.2f', $h, $m, $s,       $f);
    437438                            $thisfile_riff_WAVE['iXML'][0]['timecode_string_round'] = sprintf('%02d:%02d:%02d:%02d',   $h, $m, $s, round($f));
     439                            unset($samples_since_midnight, $timestamp_sample_rate, $h, $m, $s, $f);
    438440                        }
    439441                        unset($parsedXML);
     
    571573                            } else {
    572574                                // Short by more than one byte, throw warning
    573                                 $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
     575                                $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
    574576                                $info['avdataend'] = $info['filesize'];
    575577                            }
     
    580582                                // output file appears to be incorrectly *not* padded to nearest WORD boundary
    581583                                // Output less severe warning
    582                                 $info['warning'][] = 'File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
     584                                $this->warning('File should probably be padded to nearest WORD boundary, but it is not (expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' therefore short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
    583585                                $info['avdataend'] = $info['filesize'];
    584586                            } else {
    585587                                // Short by more than one byte, throw warning
    586                                 $info['warning'][] = 'Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)';
     588                                $this->warning('Probably truncated file - expecting '.$thisfile_riff[$RIFFsubtype]['data'][0]['size'].' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($thisfile_riff[$RIFFsubtype]['data'][0]['size'] - ($info['filesize'] - $info['avdataoffset'])).' bytes)');
    587589                                $info['avdataend'] = $info['filesize'];
    588590                            }
     
    593595                    if ((($info['avdataend'] - $info['avdataoffset']) - $info['mpeg']['audio']['LAME']['audio_bytes']) == 1) {
    594596                        $info['avdataend']--;
    595                         $info['warning'][] = 'Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored';
     597                        $this->warning('Extra null byte at end of MP3 data assumed to be RIFF padding and therefore ignored');
    596598                    }
    597599                }
     
    620622                    }
    621623                    if ($info['avdataend'] > $info['filesize']) {
    622                         $info['warning'][] = 'Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)';
     624                        $this->warning('Probably truncated file - expecting '.($info['avdataend'] - $info['avdataoffset']).' bytes of data, only found '.($info['filesize'] - $info['avdataoffset']).' (short by '.($info['avdataend'] - $info['filesize']).' bytes)');
    623625                        $info['avdataend'] = $info['filesize'];
    624626                    }
     
    661663                    $thisfile_riff_raw_avih['dwMicroSecPerFrame']    = $this->EitherEndian2Int(substr($avihData,  0, 4)); // frame display rate (or 0L)
    662664                    if ($thisfile_riff_raw_avih['dwMicroSecPerFrame'] == 0) {
    663                         $info['error'][] = 'Corrupt RIFF file: avih.dwMicroSecPerFrame == zero';
     665                        $this->error('Corrupt RIFF file: avih.dwMicroSecPerFrame == zero');
    664666                        return false;
    665667                    }
     
    859861
    860862                                        default:
    861                                             $info['warning'][] = 'Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"';
     863                                            $this->warning('Unhandled fccType for stream ('.$i.'): "'.$strhfccType.'"');
    862864                                            break;
    863865
     
    964966                            // forget to pad end of file to make this actually work
    965967                        } else {
    966                             $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
     968                            $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['SSND'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found');
    967969                        }
    968970                        $info['avdataend'] = $info['filesize'];
     
    10211023                    $thisfile_audio['sample_rate']     = $thisfile_riff_audio['sample_rate'];
    10221024                    if ($thisfile_audio['sample_rate'] == 0) {
    1023                         $info['error'][] = 'Corrupted AIFF file: sample_rate == zero';
     1025                        $this->error('Corrupted AIFF file: sample_rate == zero');
    10241026                        return false;
    10251027                    }
     
    10811083                    $info['avdataend']    = $info['avdataoffset'] + $thisfile_riff[$RIFFsubtype]['BODY'][0]['size'];
    10821084                    if ($info['avdataend'] > $info['filesize']) {
    1083                         $info['warning'][] = 'Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found';
     1085                        $this->warning('Probable truncated AIFF file: expecting '.$thisfile_riff[$RIFFsubtype]['BODY'][0]['size'].' bytes of audio data, only '.($info['filesize'] - $info['avdataoffset']).' bytes found');
    10841086                    }
    10851087                }
     
    11131115
    11141116                        default:
    1115                             $info['warning'][] = 'Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"';
     1117                            $this->warning('Unexpected sCompression value in 8SVX.VHDR chunk - expecting 0 or 1, found "'.sCompression.'"');
    11161118                            break;
    11171119                    }
     
    11311133
    11321134                        default:
    1133                             $info['warning'][] = 'Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"';
     1135                            $this->warning('Unexpected value in 8SVX.CHAN chunk - expecting 2 or 4 or 6, found "'.$ChannelsIndex.'"');
    11341136                            break;
    11351137                    }
     
    11711173                break;
    11721174
     1175            case 'WEBP':
     1176                // https://developers.google.com/speed/webp/docs/riff_container
     1177                // https://tools.ietf.org/html/rfc6386
     1178                // https://chromium.googlesource.com/webm/libwebp/+/master/doc/webp-lossless-bitstream-spec.txt
     1179                $info['fileformat'] = 'webp';
     1180                $info['mime_type']  = 'image/webp';
     1181
     1182                if (!empty($thisfile_riff['WEBP']['VP8 '][0]['size'])) {
     1183                    $old_offset = $this->ftell();
     1184                    $this->fseek($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8); // 4 bytes "VP8 " + 4 bytes chunk size
     1185                    $WEBP_VP8_header = $this->fread(10);
     1186                    $this->fseek($old_offset);
     1187                    if (substr($WEBP_VP8_header, 3, 3) == "\x9D\x01\x2A") {
     1188                        $thisfile_riff['WEBP']['VP8 '][0]['keyframe']   = !(getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x800000);
     1189                        $thisfile_riff['WEBP']['VP8 '][0]['version']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x700000) >> 20;
     1190                        $thisfile_riff['WEBP']['VP8 '][0]['show_frame'] =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x080000);
     1191                        $thisfile_riff['WEBP']['VP8 '][0]['data_bytes'] =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 0, 3)) & 0x07FFFF) >>  0;
     1192
     1193                        $thisfile_riff['WEBP']['VP8 '][0]['scale_x']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0xC000) >> 14;
     1194                        $thisfile_riff['WEBP']['VP8 '][0]['width']      =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 6, 2)) & 0x3FFF);
     1195                        $thisfile_riff['WEBP']['VP8 '][0]['scale_y']    =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0xC000) >> 14;
     1196                        $thisfile_riff['WEBP']['VP8 '][0]['height']     =  (getid3_lib::LittleEndian2Int(substr($WEBP_VP8_header, 8, 2)) & 0x3FFF);
     1197
     1198                        $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8 '][0]['width'];
     1199                        $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8 '][0]['height'];
     1200                    } else {
     1201                        $this->error('Expecting 9D 01 2A at offset '.($thisfile_riff['WEBP']['VP8 '][0]['offset'] + 8 + 3).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8_header, 3, 3)).'"');
     1202                    }
     1203
     1204                }
     1205                if (!empty($thisfile_riff['WEBP']['VP8L'][0]['size'])) {
     1206                    $old_offset = $this->ftell();
     1207                    $this->fseek($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8); // 4 bytes "VP8L" + 4 bytes chunk size
     1208                    $WEBP_VP8L_header = $this->fread(10);
     1209                    $this->fseek($old_offset);
     1210                    if (substr($WEBP_VP8L_header, 0, 1) == "\x2F") {
     1211                        $width_height_flags = getid3_lib::LittleEndian2Bin(substr($WEBP_VP8L_header, 1, 4));
     1212                        $thisfile_riff['WEBP']['VP8L'][0]['width']         =        bindec(substr($width_height_flags, 18, 14)) + 1;
     1213                        $thisfile_riff['WEBP']['VP8L'][0]['height']        =        bindec(substr($width_height_flags,  4, 14)) + 1;
     1214                        $thisfile_riff['WEBP']['VP8L'][0]['alpha_is_used'] = (bool) bindec(substr($width_height_flags,  3,  1));
     1215                        $thisfile_riff['WEBP']['VP8L'][0]['version']       =        bindec(substr($width_height_flags,  0,  3));
     1216
     1217                        $info['video']['resolution_x'] = $thisfile_riff['WEBP']['VP8L'][0]['width'];
     1218                        $info['video']['resolution_y'] = $thisfile_riff['WEBP']['VP8L'][0]['height'];
     1219                    } else {
     1220                        $this->error('Expecting 2F at offset '.($thisfile_riff['WEBP']['VP8L'][0]['offset'] + 8).', found "'.getid3_lib::PrintHexBytes(substr($WEBP_VP8L_header, 0, 1)).'"');
     1221                    }
     1222
     1223                }
     1224                break;
    11731225
    11741226            default:
    1175                 $info['error'][] = 'Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA), found "'.$RIFFsubtype.'" instead';
     1227                $this->error('Unknown RIFF type: expecting one of (WAVE|RMP3|AVI |CDDA|AIFF|AIFC|8SVX|CDXA|WEBP), found "'.$RIFFsubtype.'" instead');
    11761228                //unset($info['fileformat']);
    11771229        }
     
    11861238                    if (isset($thisfile_riff[$RIFFsubtype][$ID3v2_key_bad]) && !array_key_exists($ID3v2_key_good, $thisfile_riff[$RIFFsubtype])) {
    11871239                        $thisfile_riff[$RIFFsubtype][$ID3v2_key_good] = $thisfile_riff[$RIFFsubtype][$ID3v2_key_bad];
    1188                         $info['warning'][] = 'mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"';
     1240                        $this->warning('mapping "'.$ID3v2_key_bad.'" chunk to "'.$ID3v2_key_good.'"');
    11891241                    }
    11901242                }
     
    15101562                                            if (!empty($getid3_temp->info['warning'])) {
    15111563                                                foreach ($getid3_temp->info['warning'] as $key => $value) {
    1512                                                     $info['warning'][] = $value;
     1564                                                    $this->warning($value);
    15131565                                                }
    15141566                                            }
Note: See TracChangeset for help on using the changeset viewer.