Make WordPress Core


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

    r32979 r41196  
    2222if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) {
    2323    define('IMG_JPG', IMAGETYPE_JPEG);
     24}
     25if (!defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE
     26    define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8));
    2427}
    2528
     
    110113    protected $startup_warning = '';
    111114
    112     const VERSION           = '1.9.9-20141121';
     115    const VERSION           = '1.9.14-201706111222';
    113116    const FREAD_BUFFER_SIZE = 32768;
    114117
     
    121124        // Check memory
    122125        $this->memory_limit = ini_get('memory_limit');
    123         if (preg_match('#([0-9]+)M#i', $this->memory_limit, $matches)) {
     126        if (preg_match('#([0-9]+) ?M#i', $this->memory_limit, $matches)) {
    124127            // could be stored as "16M" rather than 16777216 for example
    125128            $this->memory_limit = $matches[1] * 1048576;
    126         } elseif (preg_match('#([0-9]+)G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
     129        } elseif (preg_match('#([0-9]+) ?G#i', $this->memory_limit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
    127130            // could be stored as "2G" rather than 2147483648 for example
    128131            $this->memory_limit = $matches[1] * 1073741824;
     
    131134            // memory limits probably disabled
    132135        } elseif ($this->memory_limit <= 4194304) {
    133             $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini';
     136            $this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n";
    134137        } elseif ($this->memory_limit <= 12582912) {
    135             $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini';
     138            $this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'."\n";
    136139        }
    137140
     
    141144        }
    142145
    143         if (intval(ini_get('mbstring.func_overload')) > 0) {
    144             $this->warning('WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", this may break things.');
     146        if (($mbstring_func_overload = ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) {
     147            // http://php.net/manual/en/mbstring.overload.php
     148            // "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions"
     149            // getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those.
     150            $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";
    145151        }
    146152
     
    148154        if (function_exists('get_magic_quotes_runtime')) {
    149155            if (get_magic_quotes_runtime()) {
    150                 return $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).');
     156                $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";
    151157            }
    152158        }
     
    155161        if (function_exists('magic_quotes_gpc')) {
    156162            if (get_magic_quotes_gpc()) {
    157                 return $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).');
     163                $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";
    158164            }
    159165        }
     
    161167        // Load support library
    162168        if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
    163             $this->startup_error .= 'getid3.lib.php is missing or corrupt';
     169            $this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n";
    164170        }
    165171
     
    180186
    181187            if (!is_dir($helperappsdir)) {
    182                 $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist';
     188                $this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n";
    183189            } elseif (strpos(realpath($helperappsdir), ' ') !== false) {
    184190                $DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
     
    200206                            }
    201207                        } else {
    202                             $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.';
     208                            $this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'."\n";
    203209                        }
    204210                    }
     
    208214            }
    209215            define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
     216        }
     217
     218        if (!empty($this->startup_error)) {
     219            echo $this->startup_error;
     220            throw new getid3_exception($this->startup_error);
    210221        }
    211222
     
    237248
    238249
    239     public function openfile($filename) {
     250    public function openfile($filename, $filesize=null) {
    240251        try {
    241252            if (!empty($this->startup_error)) {
     
    243254            }
    244255            if (!empty($this->startup_warning)) {
    245                 $this->warning($this->startup_warning);
     256                foreach (explode("\n", $this->startup_warning) as $startup_warning) {
     257                    $this->warning($startup_warning);
     258                }
    246259            }
    247260
     
    253266
    254267            // remote files not supported
    255             if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
     268            if (preg_match('#^(ht|f)tp://#', $filename)) {
    256269                throw new getid3_exception('Remote files are not supported - please copy the file locally first');
    257270            }
    258271
    259272            $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
    260             $filename = preg_replace('#(.+)'.preg_quote(DIRECTORY_SEPARATOR).'{2,}#U', '\1'.DIRECTORY_SEPARATOR, $filename);
     273            $filename = preg_replace('#(?<!gs:)('.preg_quote(DIRECTORY_SEPARATOR).'{2,})#', DIRECTORY_SEPARATOR, $filename);
    261274
    262275            // open local file
     
    281294            }
    282295
    283             $this->info['filesize'] = filesize($filename);
     296            $this->info['filesize'] = (!is_null($filesize) ? $filesize : filesize($filename));
    284297            // set redundant parameters - might be needed in some include file
    285298            // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
     
    289302            $this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
    290303
     304            // set more parameters
     305            $this->info['avdataoffset']        = 0;
     306            $this->info['avdataend']           = $this->info['filesize'];
     307            $this->info['fileformat']          = '';                // filled in later
     308            $this->info['audio']['dataformat'] = '';                // filled in later, unset if not used
     309            $this->info['video']['dataformat'] = '';                // filled in later, unset if not used
     310            $this->info['tags']                = array();           // filled in later, unset if not used
     311            $this->info['error']               = array();           // filled in later, unset if not used
     312            $this->info['warning']             = array();           // filled in later, unset if not used
     313            $this->info['comments']            = array();           // filled in later, unset if not used
     314            $this->info['encoding']            = $this->encoding;   // required by id3v2 and iso modules - can be unset at the end if desired
    291315
    292316            // option_max_2gb_check
     
    315339            }
    316340
    317             // set more parameters
    318             $this->info['avdataoffset']        = 0;
    319             $this->info['avdataend']           = $this->info['filesize'];
    320             $this->info['fileformat']          = '';                // filled in later
    321             $this->info['audio']['dataformat'] = '';                // filled in later, unset if not used
    322             $this->info['video']['dataformat'] = '';                // filled in later, unset if not used
    323             $this->info['tags']                = array();           // filled in later, unset if not used
    324             $this->info['error']               = array();           // filled in later, unset if not used
    325             $this->info['warning']             = array();           // filled in later, unset if not used
    326             $this->info['comments']            = array();           // filled in later, unset if not used
    327             $this->info['encoding']            = $this->encoding;   // required by id3v2 and iso modules - can be unset at the end if desired
    328 
    329341            return true;
    330342
     
    336348
    337349    // public: analyze file
    338     public function analyze($filename) {
     350    public function analyze($filename, $filesize=null, $original_filename='') {
    339351        try {
    340             if (!$this->openfile($filename)) {
     352            if (!$this->openfile($filename, $filesize)) {
    341353                return $this->info;
    342354            }
     
    383395
    384396            // determine format
    385             $determined_format = $this->GetFileFormat($formattest, $filename);
     397            $determined_format = $this->GetFileFormat($formattest, ($original_filename ? $original_filename : $filename));
    386398
    387399            // unable to determine file format
     
    420432            }
    421433
    422             // module requires iconv support
     434            // module requires mb_convert_encoding/iconv support
    423435            // Check encoding/iconv support
    424             if (!empty($determined_format['iconv_req']) && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
    425                 $errormessage = 'iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
     436            if (!empty($determined_format['iconv_req']) && !function_exists('mb_convert_encoding') && !function_exists('iconv') && !in_array($this->encoding, array('ISO-8859-1', 'UTF-8', 'UTF-16LE', 'UTF-16BE', 'UTF-16'))) {
     437                $errormessage = 'mb_convert_encoding() or iconv() support is required for this module ('.$determined_format['include'].') for encodings other than ISO-8859-1, UTF-8, UTF-16LE, UTF16-BE, UTF-16. ';
    426438                if (GETID3_OS_ISWINDOWS) {
    427                     $errormessage .= 'PHP does not have iconv() support. Please enable php_iconv.dll in php.ini, and copy iconv.dll from c:/php/dlls to c:/windows/system32';
     439                    $errormessage .= 'PHP does not have mb_convert_encoding() or iconv() support. Please enable php_mbstring.dll / php_iconv.dll in php.ini, and copy php_mbstring.dll / iconv.dll from c:/php/dlls to c:/windows/system32';
    428440                } else {
    429                     $errormessage .= 'PHP is not compiled with iconv() support. Please recompile with the --with-iconv switch';
     441                    $errormessage .= 'PHP is not compiled with mb_convert_encoding() or iconv() support. Please recompile with the --enable-mbstring / --with-iconv switch';
    430442                }
    431443                return $this->error($errormessage);
     
    562574                // AC-3   - audio      - Dolby AC-3 / Dolby Digital
    563575                'ac3'  => array(
    564                             'pattern'   => '^\x0B\x77',
     576                            'pattern'   => '^\\x0B\\x77',
    565577                            'group'     => 'audio',
    566578                            'module'    => 'ac3',
     
    580592                // AA   - audio       - Audible Audiobook
    581593                'aa'   => array(
    582                             'pattern'   => '^.{4}\x57\x90\x75\x36',
     594                            'pattern'   => '^.{4}\\x57\\x90\\x75\\x36',
    583595                            'group'     => 'audio',
    584596                            'module'    => 'aa',
     
    588600                // AAC  - audio       - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
    589601                'adts' => array(
    590                             'pattern'   => '^\xFF[\xF0-\xF1\xF8-\xF9]',
     602                            'pattern'   => '^\\xFF[\\xF0-\\xF1\\xF8-\\xF9]',
    591603                            'group'     => 'audio',
    592604                            'module'    => 'aac',
     
    598610                // AU   - audio       - NeXT/Sun AUdio (AU)
    599611                'au'   => array(
    600                             'pattern'   => '^\.snd',
     612                            'pattern'   => '^\\.snd',
    601613                            'group'     => 'audio',
    602614                            'module'    => 'au',
     
    606618                // AMR  - audio       - Adaptive Multi Rate
    607619                'amr'  => array(
    608                             'pattern'   => '^\x23\x21AMR\x0A', // #!AMR[0A]
     620                            'pattern'   => '^\\x23\\x21AMR\\x0A', // #!AMR[0A]
    609621                            'group'     => 'audio',
    610622                            'module'    => 'amr',
     
    622634                // BONK - audio       - Bonk v0.9+
    623635                'bonk' => array(
    624                             'pattern'   => '^\x00(BONK|INFO|META| ID3)',
     636                            'pattern'   => '^\\x00(BONK|INFO|META| ID3)',
    625637                            'group'     => 'audio',
    626638                            'module'    => 'bonk',
     
    628640                        ),
    629641
     642                // DSF  - audio       - Direct Stream Digital (DSD) Storage Facility files (DSF) - https://en.wikipedia.org/wiki/Direct_Stream_Digital
     643                'dsf'  => array(
     644                            'pattern'   => '^DSD ',  // including trailing space: 44 53 44 20
     645                            'group'     => 'audio',
     646                            'module'    => 'dsf',
     647                            'mime_type' => 'audio/dsd',
     648                        ),
     649
    630650                // DSS  - audio       - Digital Speech Standard
    631651                'dss'  => array(
    632                             'pattern'   => '^[\x02-\x03]ds[s2]',
     652                            'pattern'   => '^[\\x02-\\x06]ds[s2]',
    633653                            'group'     => 'audio',
    634654                            'module'    => 'dss',
     
    638658                // DTS  - audio       - Dolby Theatre System
    639659                'dts'  => array(
    640                             'pattern'   => '^\x7F\xFE\x80\x01',
     660                            'pattern'   => '^\\x7F\\xFE\\x80\\x01',
    641661                            'group'     => 'audio',
    642662                            'module'    => 'dts',
     
    723743                // MPC  - audio       - Musepack / MPEGplus
    724744                'mpc'  => array(
    725                             'pattern'   => '^(MPCK|MP\+|[\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])',
     745                            'pattern'   => '^(MPCK|MP\\+|[\\x00\\x01\\x10\\x11\\x40\\x41\\x50\\x51\\x80\\x81\\x90\\x91\\xC0\\xC1\\xD0\\xD1][\\x20-\\x37][\\x00\\x20\\x40\\x60\\x80\\xA0\\xC0\\xE0])',
    726746                            'group'     => 'audio',
    727747                            'module'    => 'mpc',
     
    731751                // MP3  - audio       - MPEG-audio Layer 3 (very similar to AAC-ADTS)
    732752                'mp3'  => array(
    733                             'pattern'   => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\x0B\x10-\x1B\x20-\x2B\x30-\x3B\x40-\x4B\x50-\x5B\x60-\x6B\x70-\x7B\x80-\x8B\x90-\x9B\xA0-\xAB\xB0-\xBB\xC0-\xCB\xD0-\xDB\xE0-\xEB\xF0-\xFB]',
     753                            'pattern'   => '^\\xFF[\\xE2-\\xE7\\xF2-\\xF7\\xFA-\\xFF][\\x00-\\x0B\\x10-\\x1B\\x20-\\x2B\\x30-\\x3B\\x40-\\x4B\\x50-\\x5B\\x60-\\x6B\\x70-\\x7B\\x80-\\x8B\\x90-\\x9B\\xA0-\\xAB\\xB0-\\xBB\\xC0-\\xCB\\xD0-\\xDB\\xE0-\\xEB\\xF0-\\xFB]',
    734754                            'group'     => 'audio',
    735755                            'module'    => 'mp3',
     
    739759                // OFR  - audio       - OptimFROG
    740760                'ofr'  => array(
    741                             'pattern'   => '^(\*RIFF|OFR)',
     761                            'pattern'   => '^(\\*RIFF|OFR)',
    742762                            'group'     => 'audio',
    743763                            'module'    => 'optimfrog',
     
    765785                // TTA  - audio       - TTA Lossless Audio Compressor (http://tta.corecodec.org)
    766786                'tta'  => array(
    767                             'pattern'   => '^TTA',  // could also be '^TTA(\x01|\x02|\x03|2|1)'
     787                            'pattern'   => '^TTA',  // could also be '^TTA(\\x01|\\x02|\\x03|2|1)'
    768788                            'group'     => 'audio',
    769789                            'module'    => 'tta',
     
    800820                // ASF  - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio
    801821                'asf'  => array(
    802                             'pattern'   => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C',
     822                            'pattern'   => '^\\x30\\x26\\xB2\\x75\\x8E\\x66\\xCF\\x11\\xA6\\xD9\\x00\\xAA\\x00\\x62\\xCE\\x6C',
    803823                            'group'     => 'audio-video',
    804824                            'module'    => 'asf',
     
    817837                // FLV  - audio/video - FLash Video
    818838                'flv' => array(
    819                             'pattern'   => '^FLV\x01',
     839                            'pattern'   => '^FLV[\\x01]',
    820840                            'group'     => 'audio-video',
    821841                            'module'    => 'flv',
     
    825845                // MKAV - audio/video - Mastroka
    826846                'matroska' => array(
    827                             'pattern'   => '^\x1A\x45\xDF\xA3',
     847                            'pattern'   => '^\\x1A\\x45\\xDF\\xA3',
    828848                            'group'     => 'audio-video',
    829849                            'module'    => 'matroska',
     
    833853                // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
    834854                'mpeg' => array(
    835                             'pattern'   => '^\x00\x00\x01(\xBA|\xB3)',
     855                            'pattern'   => '^\\x00\\x00\\x01[\\xB3\\xBA]',
    836856                            'group'     => 'audio-video',
    837857                            'module'    => 'mpeg',
     
    870890                            'group'     => 'audio-video',
    871891                            'module'    => 'riff',
    872                             'mime_type' => 'audio/x-wave',
     892                            'mime_type' => 'audio/x-wav',
    873893                            'fail_ape'  => 'WARNING',
    874894                        ),
     
    876896                // Real - audio/video - RealAudio, RealVideo
    877897                'real' => array(
    878                             'pattern'   => '^(\\.RMF|\\.ra)',
     898                            'pattern'   => '^\\.(RMF|ra)',
    879899                            'group'     => 'audio-video',
    880900                            'module'    => 'real',
     
    892912                // TS - audio/video - MPEG-2 Transport Stream
    893913                'ts' => array(
    894                             'pattern'   => '^(\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G".  Check for at least 10 packets matching this pattern
     914                            'pattern'   => '^(\\x47.{187}){10,}', // packets are 188 bytes long and start with 0x47 "G".  Check for at least 10 packets matching this pattern
    895915                            'group'     => 'audio-video',
    896916                            'module'    => 'ts',
     
    923943                // JPEG - still image - Joint Photographic Experts Group (JPEG)
    924944                'jpg'  => array(
    925                             'pattern'   => '^\xFF\xD8\xFF',
     945                            'pattern'   => '^\\xFF\\xD8\\xFF',
    926946                            'group'     => 'graphic',
    927947                            'module'    => 'jpg',
     
    933953                // PCD  - still image - Kodak Photo CD
    934954                'pcd'  => array(
    935                             'pattern'   => '^.{2048}PCD_IPI\x00',
     955                            'pattern'   => '^.{2048}PCD_IPI\\x00',
    936956                            'group'     => 'graphic',
    937957                            'module'    => 'pcd',
     
    944964                // PNG  - still image - Portable Network Graphics (PNG)
    945965                'png'  => array(
    946                             'pattern'   => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A',
     966                            'pattern'   => '^\\x89\\x50\\x4E\\x47\\x0D\\x0A\\x1A\\x0A',
    947967                            'group'     => 'graphic',
    948968                            'module'    => 'png',
     
    955975                // SVG  - still image - Scalable Vector Graphics (SVG)
    956976                'svg'  => array(
    957                             'pattern'   => '(<!DOCTYPE svg PUBLIC |xmlns="http:\/\/www\.w3\.org\/2000\/svg")',
     977                            'pattern'   => '(<!DOCTYPE svg PUBLIC |xmlns="http://www\\.w3\\.org/2000/svg")',
    958978                            'group'     => 'graphic',
    959979                            'module'    => 'svg',
     
    966986                // TIFF - still image - Tagged Information File Format (TIFF)
    967987                'tiff' => array(
    968                             'pattern'   => '^(II\x2A\x00|MM\x00\x2A)',
     988                            'pattern'   => '^(II\\x2A\\x00|MM\\x00\\x2A)',
    969989                            'group'     => 'graphic',
    970990                            'module'    => 'tiff',
     
    977997                // EFAX - still image - eFax (TIFF derivative)
    978998                'efax'  => array(
    979                             'pattern'   => '^\xDC\xFE',
     999                            'pattern'   => '^\\xDC\\xFE',
    9801000                            'group'     => 'graphic',
    9811001                            'module'    => 'efax',
     
    10011021                // RAR  - data        - RAR compressed data
    10021022                'rar'  => array(
    1003                             'pattern'   => '^Rar\!',
     1023                            'pattern'   => '^Rar\\!',
    10041024                            'group'     => 'archive',
    10051025                            'module'    => 'rar',
     
    10111031                // SZIP - audio/data  - SZIP compressed data
    10121032                'szip' => array(
    1013                             'pattern'   => '^SZ\x0A\x04',
     1033                            'pattern'   => '^SZ\\x0A\\x04',
    10141034                            'group'     => 'archive',
    10151035                            'module'    => 'szip',
     
    10211041                // TAR  - data        - TAR compressed data
    10221042                'tar'  => array(
    1023                             'pattern'   => '^.{100}[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20]{7}\x00[0-9\x20\x00]{12}[0-9\x20\x00]{12}',
     1043                            'pattern'   => '^.{100}[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20]{7}\\x00[0-9\\x20\\x00]{12}[0-9\\x20\\x00]{12}',
    10241044                            'group'     => 'archive',
    10251045                            'module'    => 'tar',
     
    10311051                // GZIP  - data        - GZIP compressed data
    10321052                'gz'  => array(
    1033                             'pattern'   => '^\x1F\x8B\x08',
     1053                            'pattern'   => '^\\x1F\\x8B\\x08',
    10341054                            'group'     => 'archive',
    10351055                            'module'    => 'gzip',
     
    10411061                // ZIP  - data         - ZIP compressed data
    10421062                'zip'  => array(
    1043                             'pattern'   => '^PK\x03\x04',
     1063                            'pattern'   => '^PK\\x03\\x04',
    10441064                            'group'     => 'archive',
    10451065                            'module'    => 'zip',
     
    10541074                // PAR2 - data        - Parity Volume Set Specification 2.0
    10551075                'par2' => array (
    1056                             'pattern'   => '^PAR2\x00PKT',
     1076                            'pattern'   => '^PAR2\\x00PKT',
    10571077                            'group'     => 'misc',
    10581078                            'module'    => 'par2',
     
    10641084                // PDF  - data        - Portable Document Format
    10651085                'pdf'  => array(
    1066                             'pattern'   => '^\x25PDF',
     1086                            'pattern'   => '^\\x25PDF',
    10671087                            'group'     => 'misc',
    10681088                            'module'    => 'pdf',
     
    10741094                // MSOFFICE  - data   - ZIP compressed data
    10751095                'msoffice' => array(
    1076                             'pattern'   => '^\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
     1096                            'pattern'   => '^\\xD0\\xCF\\x11\\xE0\\xA1\\xB1\\x1A\\xE1', // D0CF11E == DOCFILE == Microsoft Office Document
    10771097                            'group'     => 'misc',
    10781098                            'module'    => 'msoffice',
     
    11151135
    11161136
    1117         if (preg_match('#\.mp[123a]$#i', $filename)) {
     1137        if (preg_match('#\\.mp[123a]$#i', $filename)) {
    11181138            // Too many mp3 encoders on the market put gabage in front of mpeg files
    11191139            // use assume format on these if format detection failed
     
    11221142            $info['include'] = 'module.'.$info['group'].'.'.$info['module'].'.php';
    11231143            return $info;
    1124         } elseif (preg_match('/\.cue$/i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
     1144        } elseif (preg_match('#\\.cue$#i', $filename) && preg_match('#FILE "[^"]+" (BINARY|MOTOROLA|AIFF|WAVE|MP3)#', $filedata)) {
    11251145            // there's not really a useful consistent "magic" at the beginning of .cue files to identify them
    11261146            // so until I think of something better, just go by filename if all other format checks fail
     
    12231243                }
    12241244
     1245                $this->CharConvert($this->info['tags'][$tag_name], $this->info[$comment_name]['encoding']);           // only copy gets converted!
     1246
    12251247                if ($this->option_tags_html) {
    12261248                    foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
    1227                         $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $encoding);
     1249                        $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']);
    12281250                    }
    12291251                }
    12301252
    1231                 $this->CharConvert($this->info['tags'][$tag_name], $encoding);           // only copy gets converted!
    12321253            }
    12331254
     
    13531374                if (!empty($VorbisCommentError)) {
    13541375
    1355                     $this->info['warning'][]         = 'Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError;
    1356                     $this->info[$algorithm.'_data']  = false;
     1376                    $this->warning('Failed making system call to vorbiscomment(.exe) - '.$algorithm.'_data will be incorrect. If vorbiscomment is unavailable, please download from http://www.vorbis.com/download.psp and put in the getID3() directory. Error returned: '.$VorbisCommentError);
     1377                    $this->info[$algorithm.'_data'] = false;
    13571378
    13581379                } else {
     
    15831604    }
    15841605
     1606    public static function is_writable ($filename) {
     1607        $ret = is_writable($filename);
     1608
     1609        if (!$ret) {
     1610            $perms = fileperms($filename);
     1611            $ret = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002);
     1612        }
     1613
     1614        return $ret;
     1615    }
     1616
    15851617}
    15861618
     
    16621694            throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
    16631695        }
    1664         return fread($this->getid3->fp, $bytes);
     1696
     1697        //return fread($this->getid3->fp, $bytes);
     1698        /*
     1699        * http://www.getid3.org/phpBB3/viewtopic.php?t=1930
     1700        * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread().
     1701        * It seems to assume that fread() would always return as many bytes as were requested.
     1702        * However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes.
     1703        * The call may return only part of the requested data and a new call is needed to get more."
     1704        */
     1705        $contents = '';
     1706        do {
     1707            $part = fread($this->getid3->fp, $bytes);
     1708            $partLength  = strlen($part);
     1709            $bytes      -= $partLength;
     1710            $contents   .= $part;
     1711        } while (($bytes > 0) && ($partLength > 0));
     1712        return $contents;
    16651713    }
    16661714
     
    17421790                // set up destination path
    17431791                $dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR);
    1744                 if (!is_dir($dir) || !is_writable($dir)) { // check supplied directory
     1792                if (!is_dir($dir) || !getID3::is_writable($dir)) { // check supplied directory
    17451793                    throw new Exception('supplied path ('.$dir.') does not exist, or is not writable');
    17461794                }
Note: See TracChangeset for help on using the changeset viewer.