Make WordPress Core


Ignore:
Timestamp:
09/14/2019 07:06:09 PM (6 years ago)
Author:
jorbin
Message:

Update getID3 library to fix issues with PHP7.4

Updates to trunk version that includes fixes for PHP7.4

Changelog:
https://github.com/JamesHeinrich/getID3/compare/v1.9.14...00f3fbfd77e583099ca70a3cf0bc092e113d2b20

See: #47751,#47783.
Fixes: #48040.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/getid3.php

    r41196 r46112  
    22/////////////////////////////////////////////////////////////////
    33/// getID3() by James Heinrich <info@getid3.org>               //
    4 //  available at http://getid3.sourceforge.net                 //
    5 //            or http://www.getid3.org                         //
    6 //          also https://github.com/JamesHeinrich/getID3       //
    7 /////////////////////////////////////////////////////////////////
     4//  available at https://github.com/JamesHeinrich/getID3       //
     5//            or https://www.getid3.org                        //
     6//            or http://getid3.sourceforge.net                 //
    87//                                                             //
    98// Please see readme.txt for more information                  //
     
    2625    define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8));
    2726}
     27
     28/*
     29https://www.getid3.org/phpBB3/viewtopic.php?t=2114
     30If you are running into a the problem where filenames with special characters are being handled
     31incorrectly by external helper programs (e.g. metaflac), notably with the special characters removed,
     32and you are passing in the filename in UTF8 (typically via a HTML form), try uncommenting this line:
     33*/
     34//setlocale(LC_CTYPE, 'en_US.UTF-8');
    2835
    2936// attempt to define temp dir as something flexible but reliable
     
    7582class getID3
    7683{
    77     // public: Settings
    78     public $encoding        = 'UTF-8';        // CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples:  ISO-8859-1  UTF-8  UTF-16  UTF-16BE
    79     public $encoding_id3v1  = 'ISO-8859-1';   // Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
    80 
    81     // public: Optional tag checks - disable for speed.
    82     public $option_tag_id3v1         = true;  // Read and process ID3v1 tags
    83     public $option_tag_id3v2         = true;  // Read and process ID3v2 tags
    84     public $option_tag_lyrics3       = true;  // Read and process Lyrics3 tags
    85     public $option_tag_apetag        = true;  // Read and process APE tags
    86     public $option_tags_process      = true;  // Copy tags to root key 'tags' and encode to $this->encoding
    87     public $option_tags_html         = true;  // Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
    88 
    89     // public: Optional tag/comment calucations
    90     public $option_extra_info        = true;  // Calculate additional info such as bitrate, channelmode etc
    91 
    92     // public: Optional handling of embedded attachments (e.g. images)
    93     public $option_save_attachments  = true; // defaults to true (ATTACHMENTS_INLINE) for backward compatibility
    94 
    95     // public: Optional calculations
    96     public $option_md5_data          = false; // Get MD5 sum of data part - slow
    97     public $option_md5_data_source   = false; // Use MD5 of source file if availble - only FLAC and OptimFROG
    98     public $option_sha1_data         = false; // Get SHA1 sum of data part - slow
    99     public $option_max_2gb_check     = null;  // Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on PHP_INT_MAX)
    100 
    101     // public: Read buffer size in bytes
     84    /*
     85     * Settings
     86     */
     87
     88    /**
     89     * CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples:  ISO-8859-1  UTF-8  UTF-16  UTF-16BE
     90     *
     91     * @var string
     92     */
     93    public $encoding        = 'UTF-8';
     94
     95    /**
     96     * Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
     97     *
     98     * @var string
     99     */
     100    public $encoding_id3v1  = 'ISO-8859-1';
     101
     102    /*
     103     * Optional tag checks - disable for speed.
     104     */
     105
     106    /**
     107     * Read and process ID3v1 tags
     108     *
     109     * @var bool
     110     */
     111    public $option_tag_id3v1         = true;
     112
     113    /**
     114     * Read and process ID3v2 tags
     115     *
     116     * @var bool
     117     */
     118    public $option_tag_id3v2         = true;
     119
     120    /**
     121     * Read and process Lyrics3 tags
     122     *
     123     * @var bool
     124     */
     125    public $option_tag_lyrics3       = true;
     126
     127    /**
     128     * Read and process APE tags
     129     *
     130     * @var bool
     131     */
     132    public $option_tag_apetag        = true;
     133
     134    /**
     135     * Copy tags to root key 'tags' and encode to $this->encoding
     136     *
     137     * @var bool
     138     */
     139    public $option_tags_process      = true;
     140
     141    /**
     142     * Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
     143     *
     144     * @var bool
     145     */
     146    public $option_tags_html         = true;
     147
     148    /*
     149     * Optional tag/comment calculations
     150     */
     151
     152    /**
     153     * Calculate additional info such as bitrate, channelmode etc
     154     *
     155     * @var bool
     156     */
     157    public $option_extra_info        = true;
     158
     159    /*
     160     * Optional handling of embedded attachments (e.g. images)
     161     */
     162
     163    /**
     164     * Defaults to true (ATTACHMENTS_INLINE) for backward compatibility
     165     *
     166     * @var bool|string
     167     */
     168    public $option_save_attachments  = true;
     169
     170    /*
     171     * Optional calculations
     172     */
     173
     174    /**
     175     * Get MD5 sum of data part - slow
     176     *
     177     * @var bool
     178     */
     179    public $option_md5_data          = false;
     180
     181    /**
     182     * Use MD5 of source file if availble - only FLAC and OptimFROG
     183     *
     184     * @var bool
     185     */
     186    public $option_md5_data_source   = false;
     187
     188    /**
     189     * Get SHA1 sum of data part - slow
     190     *
     191     * @var bool
     192     */
     193    public $option_sha1_data         = false;
     194
     195    /**
     196     * Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on
     197     * PHP_INT_MAX)
     198     *
     199     * @var bool|null
     200     */
     201    public $option_max_2gb_check;
     202
     203    /**
     204     * Read buffer size in bytes
     205     *
     206     * @var int
     207     */
    102208    public $option_fread_buffer_size = 32768;
    103209
    104210    // Public variables
    105     public $filename;                         // Filename of file being analysed.
    106     public $fp;                               // Filepointer to file being analysed.
    107     public $info;                             // Result array.
     211
     212    /**
     213     * Filename of file being analysed.
     214     *
     215     * @var string
     216     */
     217    public $filename;
     218
     219    /**
     220     * Filepointer to file being analysed.
     221     *
     222     * @var resource
     223     */
     224    public $fp;
     225
     226    /**
     227     * Result array.
     228     *
     229     * @var array
     230     */
     231    public $info;
     232
     233    /**
     234     * @var string
     235     */
    108236    public $tempdir = GETID3_TEMP_DIR;
     237
     238    /**
     239     * @var int
     240     */
    109241    public $memory_limit = 0;
    110242
    111     // Protected variables
     243    /**
     244     * @var string
     245     */
    112246    protected $startup_error   = '';
     247
     248    /**
     249     * @var string
     250     */
    113251    protected $startup_warning = '';
    114252
    115     const VERSION           = '1.9.14-201706111222';
     253    const VERSION           = '1.9.17-201907240906';
    116254    const FREAD_BUFFER_SIZE = 32768;
    117255
     
    119257    const ATTACHMENTS_INLINE = true;
    120258
    121     // public: constructor
    122259    public function __construct() {
     260
     261        // Check for PHP version
     262        $required_php_version = '5.3.0';
     263        if (version_compare(PHP_VERSION, $required_php_version, '<')) {
     264            $this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n";
     265            return;
     266        }
    123267
    124268        // Check memory
     
    177321        // Needed for Windows only:
    178322        // Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
    179         //   as well as other helper functions such as head, tail, md5sum, etc
     323        //   as well as other helper functions such as head, etc
    180324        // This path cannot contain spaces, but the below code will attempt to get the
    181325        //   8.3-equivalent path automatically
     
    220364            throw new getid3_exception($this->startup_error);
    221365        }
    222 
    223         return true;
    224     }
    225 
     366    }
     367
     368    /**
     369     * @return string
     370     */
    226371    public function version() {
    227372        return self::VERSION;
    228373    }
    229374
     375    /**
     376     * @return int
     377     */
    230378    public function fread_buffer_size() {
    231379        return $this->option_fread_buffer_size;
    232380    }
    233381
    234 
    235     // public: setOption
     382    /**
     383     * @param array $optArray
     384     *
     385     * @return bool
     386     */
    236387    public function setOption($optArray) {
    237388        if (!is_array($optArray) || empty($optArray)) {
     
    247398    }
    248399
    249 
    250     public function openfile($filename, $filesize=null) {
     400    /**
     401     * @param string $filename
     402     * @param int    $filesize
     403     *
     404     * @return bool
     405     *
     406     * @throws getid3_exception
     407     */
     408    public function openfile($filename, $filesize=null, $fp=null) {
    251409        try {
    252410            if (!empty($this->startup_error)) {
     
    271429
    272430            $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
    273             $filename = preg_replace('#(?<!gs:)('.preg_quote(DIRECTORY_SEPARATOR).'{2,})#', DIRECTORY_SEPARATOR, $filename);
     431            //$filename = preg_replace('#(?<!gs:)('.preg_quote(DIRECTORY_SEPARATOR).'{2,})#', DIRECTORY_SEPARATOR, $filename);
    274432
    275433            // open local file
    276             //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720
    277             if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
     434            //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see https://www.getid3.org/phpBB3/viewtopic.php?t=1720
     435            if (($fp != null) && ((get_resource_type($fp) == 'file') || (get_resource_type($fp) == 'stream'))) {
     436                $this->fp = $fp;
     437            } elseif ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
    278438                // great
    279439            } else {
     
    332492                            unset($this->info['filesize']);
    333493                            fclose($this->fp);
    334                             throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize, 3).'GB, please report to info@getid3.org');
     494                            throw new getid3_exception('PHP seems to think the file is larger than '.round(PHP_INT_MAX / 1073741824).'GB, but filesystem reports it as '.number_format($real_filesize / 1073741824, 3).'GB, please report to info@getid3.org');
    335495                        }
    336496                        $this->info['filesize'] = $real_filesize;
    337                         $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize, 3).'GB) and is not properly supported by PHP.');
     497                        $this->warning('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB (filesystem reports it as '.number_format($real_filesize / 1073741824, 3).'GB) and is not properly supported by PHP.');
    338498                }
    339499            }
     
    347507    }
    348508
    349     // public: analyze file
    350     public function analyze($filename, $filesize=null, $original_filename='') {
     509    /**
     510     * analyze file
     511     *
     512     * @param string $filename
     513     * @param int    $filesize
     514     * @param string $original_filename
     515     *
     516     * @return array
     517     */
     518    public function analyze($filename, $filesize=null, $original_filename='', $fp=null) {
    351519        try {
    352             if (!$this->openfile($filename, $filesize)) {
     520            if (!$this->openfile($filename, $filesize, $fp)) {
    353521                return $this->info;
    354522            }
     
    384552                if ((substr($header, 0, 3) == 'ID3') && (strlen($header) == 10)) {
    385553                    $this->info['id3v2']['header']        = true;
    386                     $this->info['id3v2']['majorversion']  = ord($header{3});
    387                     $this->info['id3v2']['minorversion']  = ord($header{4});
     554                    $this->info['id3v2']['majorversion']  = ord($header[3]);
     555                    $this->info['id3v2']['minorversion']  = ord($header[4]);
    388556                    $this->info['avdataoffset']          += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length
    389557                }
     
    498666
    499667
    500     // private: error handling
     668    /**
     669     * Error handling.
     670     *
     671     * @param string $message
     672     *
     673     * @return array
     674     */
    501675    public function error($message) {
    502676        $this->CleanUp();
     
    509683
    510684
    511     // private: warning handling
     685    /**
     686     * Warning handling.
     687     *
     688     * @param string $message
     689     *
     690     * @return bool
     691     */
    512692    public function warning($message) {
    513693        $this->info['warning'][] = $message;
     
    516696
    517697
    518     // private: CleanUp
     698    /**
     699     * @return bool
     700     */
    519701    private function CleanUp() {
    520702
     
    563745    }
    564746
    565 
    566     // return array containing information about all supported formats
     747    /**
     748     * Return array containing information about all supported formats.
     749     *
     750     * @return array
     751     */
    567752    public function GetFileFormatArray() {
    568753        static $format_info = array();
     
    585770                            'group'     => 'audio',
    586771                            'module'    => 'aac',
    587                             'mime_type' => 'application/octet-stream',
     772                            'mime_type' => 'audio/aac',
    588773                            'fail_ape'  => 'WARNING',
    589774                        ),
     
    603788                            'group'     => 'audio',
    604789                            'module'    => 'aac',
    605                             'mime_type' => 'application/octet-stream',
     790                            'mime_type' => 'audio/aac',
    606791                            'fail_ape'  => 'WARNING',
    607792                        ),
     
    650835                // DSS  - audio       - Digital Speech Standard
    651836                'dss'  => array(
    652                             'pattern'   => '^[\\x02-\\x06]ds[s2]',
     837                            'pattern'   => '^[\\x02-\\x08]ds[s2]',
    653838                            'group'     => 'audio',
    654839                            'module'    => 'dss',
     
    669854                            'group'     => 'audio',
    670855                            'module'    => 'flac',
    671                             'mime_type' => 'audio/x-flac',
     856                            'mime_type' => 'audio/flac',
    672857                        ),
    673858
     
    701886                            'group'     => 'audio',
    702887                            'module'    => 'monkey',
    703                             'mime_type' => 'application/octet-stream',
     888                            'mime_type' => 'audio/x-monkeys-audio',
    704889                        ),
    705890
     
    8901075                            'group'     => 'audio-video',
    8911076                            'module'    => 'riff',
    892                             'mime_type' => 'audio/x-wav',
     1077                            'mime_type' => 'audio/wav',
    8931078                            'fail_ape'  => 'WARNING',
    8941079                        ),
     
    10541239                            'group'     => 'archive',
    10551240                            'module'    => 'gzip',
    1056                             'mime_type' => 'application/x-gzip',
     1241                            'mime_type' => 'application/gzip',
    10571242                            'fail_id3'  => 'ERROR',
    10581243                            'fail_ape'  => 'ERROR',
     
    10691254                        ),
    10701255
     1256                // XZ   - data         - XZ compressed data
     1257                'xz'  => array(
     1258                            'pattern'   => '^\\xFD7zXZ\\x00',
     1259                            'group'     => 'archive',
     1260                            'module'    => 'xz',
     1261                            'mime_type' => 'application/x-xz',
     1262                            'fail_id3'  => 'ERROR',
     1263                            'fail_ape'  => 'ERROR',
     1264                        ),
     1265
    10711266
    10721267                // Misc other formats
     
    11161311    }
    11171312
    1118 
    1119 
     1313    /**
     1314     * @param string $filedata
     1315     * @param string $filename
     1316     *
     1317     * @return mixed|false
     1318     */
    11201319    public function GetFileFormat(&$filedata, $filename='') {
    11211320        // this function will determine the format of a file based on usually
     
    11361335
    11371336        if (preg_match('#\\.mp[123a]$#i', $filename)) {
    1138             // Too many mp3 encoders on the market put gabage in front of mpeg files
     1337            // Too many mp3 encoders on the market put garbage in front of mpeg files
    11391338            // use assume format on these if format detection failed
    11401339            $GetFileFormatArray = $this->GetFileFormatArray();
     
    11551354    }
    11561355
    1157 
    1158     // converts array to $encoding charset from $this->encoding
     1356    /**
     1357     * Converts array to $encoding charset from $this->encoding.
     1358     *
     1359     * @param array  $array
     1360     * @param string $encoding
     1361     */
    11591362    public function CharConvert(&$array, $encoding) {
    11601363
     
    11791382    }
    11801383
    1181 
     1384    /**
     1385     * @return bool
     1386     */
    11821387    public function HandleAllTags() {
    11831388
     
    12341439                    }
    12351440                    if ($tag_key == 'picture') {
     1441                        // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere
    12361442                        unset($this->info[$comment_name]['comments'][$tag_key]);
    12371443                    }
     
    12471453                if ($this->option_tags_html) {
    12481454                    foreach ($this->info['tags'][$tag_name] as $tag_key => $valuearray) {
     1455                        if ($tag_key == 'picture') {
     1456                            // Do not to try to convert binary picture data to HTML
     1457                            // https://github.com/JamesHeinrich/getID3/issues/178
     1458                            continue;
     1459                        }
    12491460                        $this->info['tags_html'][$tag_name][$tag_key] = getid3_lib::recursiveMultiByteCharString2HTML($valuearray, $this->info[$comment_name]['encoding']);
    12501461                    }
     
    12551466        }
    12561467
    1257         // pictures can take up a lot of space, and we don't need multiple copies of them
    1258         // let there be a single copy in [comments][picture], and not elsewhere
     1468        // pictures can take up a lot of space, and we don't need multiple copies of them; let there be a single copy in [comments][picture], and not elsewhere
    12591469        if (!empty($this->info['tags'])) {
    12601470            $unset_keys = array('tags', 'tags_html');
     
    13021512    }
    13031513
     1514    /**
     1515     * @param string $algorithm
     1516     *
     1517     * @return array|bool
     1518     */
    13041519    public function getHashdata($algorithm) {
    13051520        switch ($algorithm) {
     
    13661581                } else {
    13671582
    1368                     $commandline = 'vorbiscomment -w -c "'.$empty.'" "'.$file.'" "'.$temp.'" 2>&1';
    13691583                    $commandline = 'vorbiscomment -w -c '.escapeshellarg($empty).' '.escapeshellarg($file).' '.escapeshellarg($temp).' 2>&1';
    13701584                    $VorbisCommentError = `$commandline`;
     
    14241638        return true;
    14251639    }
    1426 
    14271640
    14281641    public function ChannelsBitratePlaytimeCalculations() {
     
    14901703    }
    14911704
    1492 
     1705    /**
     1706     * @return bool
     1707     */
    14931708    public function CalculateCompressionRatioVideo() {
    14941709        if (empty($this->info['video'])) {
     
    15381753    }
    15391754
    1540 
     1755    /**
     1756     * @return bool
     1757     */
    15411758    public function CalculateCompressionRatioAudio() {
    15421759        if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) {
     
    15551772    }
    15561773
    1557 
     1774    /**
     1775     * @return bool
     1776     */
    15581777    public function CalculateReplayGain() {
    15591778        if (isset($this->info['replay_gain'])) {
    15601779            if (!isset($this->info['replay_gain']['reference_volume'])) {
    1561                 $this->info['replay_gain']['reference_volume'] = (double) 89.0;
     1780                $this->info['replay_gain']['reference_volume'] = 89.0;
    15621781            }
    15631782            if (isset($this->info['replay_gain']['track']['adjustment'])) {
     
    15781797    }
    15791798
     1799    /**
     1800     * @return bool
     1801     */
    15801802    public function ProcessAudioStreams() {
    15811803        if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
     
    15911813    }
    15921814
     1815    /**
     1816     * @return string|bool
     1817     */
    15931818    public function getid3_tempnam() {
    15941819        return tempnam($this->tempdir, 'gI3');
    15951820    }
    15961821
     1822    /**
     1823     * @param string $name
     1824     *
     1825     * @return bool
     1826     *
     1827     * @throws getid3_exception
     1828     */
    15971829    public function include_module($name) {
    15981830        //if (!file_exists($this->include_path.'module.'.$name.'.php')) {
     
    16041836    }
    16051837
    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     }
     1838    /**
     1839     * @param string $filename
     1840     *
     1841     * @return bool
     1842     */
     1843    public static function is_writable ($filename) {
     1844        $ret = is_writable($filename);
     1845        if (!$ret) {
     1846            $perms = fileperms($filename);
     1847            $ret = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002);
     1848        }
     1849        return $ret;
     1850    }
    16161851
    16171852}
    16181853
    16191854
    1620 abstract class getid3_handler {
     1855abstract class getid3_handler
     1856{
    16211857
    16221858    /**
     
    16251861    protected $getid3;                       // pointer
    16261862
    1627     protected $data_string_flag     = false; // analyzing filepointer or string
    1628     protected $data_string          = '';    // string to analyze
    1629     protected $data_string_position = 0;     // seek position in string
    1630     protected $data_string_length   = 0;     // string length
    1631 
    1632     private $dependency_to = null;
    1633 
    1634 
     1863    /**
     1864     * Analyzing filepointer or string.
     1865     *
     1866     * @var bool
     1867     */
     1868    protected $data_string_flag     = false;
     1869
     1870    /**
     1871     * String to analyze.
     1872     *
     1873     * @var string
     1874     */
     1875    protected $data_string          = '';
     1876
     1877    /**
     1878     * Seek position in string.
     1879     *
     1880     * @var int
     1881     */
     1882    protected $data_string_position = 0;
     1883
     1884    /**
     1885     * String length.
     1886     *
     1887     * @var int
     1888     */
     1889    protected $data_string_length   = 0;
     1890
     1891    /**
     1892     * @var string
     1893     */
     1894    private $dependency_to;
     1895
     1896    /**
     1897     * getid3_handler constructor.
     1898     *
     1899     * @param getID3 $getid3
     1900     * @param string $call_module
     1901     */
    16351902    public function __construct(getID3 $getid3, $call_module=null) {
    16361903        $this->getid3 = $getid3;
     
    16411908    }
    16421909
    1643 
    1644     // Analyze from file pointer
     1910    /**
     1911     * Analyze from file pointer.
     1912     *
     1913     * @return bool
     1914     */
    16451915    abstract public function Analyze();
    16461916
    1647 
    1648     // Analyze from string instead
     1917    /**
     1918     * Analyze from string instead.
     1919     *
     1920     * @param string $string
     1921     */
    16491922    public function AnalyzeString($string) {
    16501923        // Enter string mode
     
    16721945    }
    16731946
     1947    /**
     1948     * @param string $string
     1949     */
    16741950    public function setStringMode($string) {
    16751951        $this->data_string_flag   = true;
     
    16781954    }
    16791955
     1956    /**
     1957     * @return int|bool
     1958     */
    16801959    protected function ftell() {
    16811960        if ($this->data_string_flag) {
     
    16851964    }
    16861965
     1966    /**
     1967     * @param int $bytes
     1968     *
     1969     * @return string|false
     1970     *
     1971     * @throws getid3_exception
     1972     */
    16871973    protected function fread($bytes) {
    16881974        if ($this->data_string_flag) {
     
    16971983        //return fread($this->getid3->fp, $bytes);
    16981984        /*
    1699         * http://www.getid3.org/phpBB3/viewtopic.php?t=1930
     1985        * https://www.getid3.org/phpBB3/viewtopic.php?t=1930
    17001986        * "I found out that the root cause for the problem was how getID3 uses the PHP system function fread().
    17011987        * It seems to assume that fread() would always return as many bytes as were requested.
     
    17051991        $contents = '';
    17061992        do {
     1993            //if (($this->getid3->memory_limit > 0) && ($bytes > $this->getid3->memory_limit)) {
     1994            if (($this->getid3->memory_limit > 0) && (($bytes / $this->getid3->memory_limit) > 0.99)) { // enable a more-fuzzy match to prevent close misses generating errors like "PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554464 bytes)"
     1995                throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') that is more than available PHP memory ('.$this->getid3->memory_limit.')', 10);
     1996            }
    17071997            $part = fread($this->getid3->fp, $bytes);
    17081998            $partLength  = strlen($part);
     
    17132003    }
    17142004
     2005    /**
     2006     * @param int $bytes
     2007     * @param int $whence
     2008     *
     2009     * @return int
     2010     *
     2011     * @throws getid3_exception
     2012     */
    17152013    protected function fseek($bytes, $whence=SEEK_SET) {
    17162014        if ($this->data_string_flag) {
     
    17432041    }
    17442042
     2043    /**
     2044     * @return bool
     2045     */
    17452046    protected function feof() {
    17462047        if ($this->data_string_flag) {
     
    17502051    }
    17512052
     2053    /**
     2054     * @param string $module
     2055     *
     2056     * @return bool
     2057     */
    17522058    final protected function isDependencyFor($module) {
    17532059        return $this->dependency_to == $module;
    17542060    }
    17552061
     2062    /**
     2063     * @param string $text
     2064     *
     2065     * @return bool
     2066     */
    17562067    protected function error($text) {
    17572068        $this->getid3->info['error'][] = $text;
     
    17602071    }
    17612072
     2073    /**
     2074     * @param string $text
     2075     *
     2076     * @return bool
     2077     */
    17622078    protected function warning($text) {
    17632079        return $this->getid3->warning($text);
    17642080    }
    17652081
     2082    /**
     2083     * @param string $text
     2084     */
    17662085    protected function notice($text) {
    17672086        // does nothing for now
    17682087    }
    17692088
     2089    /**
     2090     * @param string $name
     2091     * @param int    $offset
     2092     * @param int    $length
     2093     * @param string $image_mime
     2094     *
     2095     * @return string|null
     2096     *
     2097     * @throws Exception
     2098     * @throws getid3_exception
     2099     */
    17702100    public function saveAttachment($name, $offset, $length, $image_mime=null) {
    17712101        try {
     
    18212151            if (isset($fp_dest) && is_resource($fp_dest)) {
    18222152                fclose($fp_dest);
     2153            }
     2154
     2155            if (isset($dest) && file_exists($dest)) {
    18232156                unlink($dest);
    18242157            }
Note: See TracChangeset for help on using the changeset viewer.