Skip to content
Permalink
Browse files

bugfix: #1845 - problems with unlimited PHP memory

  • Loading branch information...
JamesHeinrich committed Jul 18, 2014
1 parent 5ac2e1f commit a99b19fdceb5c5d92648334757020445fb139b13
Showing with 11 additions and 8 deletions.
  1. +3 −0 changelog.txt
  2. +2 −2 getid3/getid3.php
  3. +2 −2 getid3/module.archive.gzip.php
  4. +4 −4 getid3/module.audio-video.quicktime.php
@@ -18,6 +18,9 @@
Version History
===============

1.9.9: [2014-??-??] James Heinrich
* Bugfix: (#1845) Quicktime parsing with no PHP memory_limit

1.9.8: [2014-05-11] James Heinrich
» Add support for AMR (Adaptive Multi-Rate audio codec)
new file: module.audio.amr.php
@@ -109,7 +109,7 @@ class getID3
protected $startup_error = '';
protected $startup_warning = '';
const VERSION = '1.9.8-20140511';
const VERSION = '1.9.9-20140718';
const FREAD_BUFFER_SIZE = 32768;
const ATTACHMENTS_NONE = false;
@@ -256,7 +256,7 @@ public function openfile($filename) {
$this->filename = $filename;
$this->info = array();
$this->info['GETID3_VERSION'] = $this->version();
$this->info['php_memory_limit'] = $this->memory_limit;
$this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false);
// remote files not supported
if (preg_match('/^(ht|f)tp:\/\//', $filename)) {
@@ -36,7 +36,7 @@ public function Analyze() {
//|ID1|ID2|CM |FLG| MTIME |XFL|OS |
//+---+---+---+---+---+---+---+---+---+---+
if ($info['filesize'] > $info['php_memory_limit']) {
if ($info['php_memory_limit'] && ($info['filesize'] > $info['php_memory_limit'])) {
$info['error'][] = 'File is too large ('.number_format($info['filesize']).' bytes) to read into memory (limit: '.number_format($info['php_memory_limit'] / 1048576).'MB)';
return false;
}
@@ -56,7 +56,7 @@ public function Analyze() {
$attr = unpack($unpack_header, substr($buf, 0, $start_length));
if (!$this->get_os_type(ord($attr['os']))) {
// Merge member with previous if wrong OS type
$arr_members[$i - 1] .= $buf;
$arr_members[($i - 1)] .= $buf;
$arr_members[$i] = '';
$is_wrong_members = true;
continue;
@@ -35,7 +35,7 @@ public function Analyze() {
$offset = 0;
$atomcounter = 0;
$atom_data_read_buffer_size = ($info['php_memory_limit'] ? round($info['php_memory_limit'] / 2) : $this->getid3->option_fread_buffer_size * 1024); // allow [default: 32MB] if PHP configured with no memory_limit
while ($offset < $info['avdataend']) {
if (!getid3_lib::intValueSupported($offset)) {
$info['error'][] = 'Unable to parse atom at offset '.$offset.' because beyond '.round(PHP_INT_MAX / 1073741824).'GB limit of PHP filesystem functions';
@@ -68,7 +68,7 @@ public function Analyze() {
break;
}
$atomHierarchy = array();
$info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, round($this->getid3->memory_limit / 2))), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
$info['quicktime'][$atomname] = $this->QuicktimeParseAtom($atomname, $atomsize, $this->fread(min($atomsize, $atom_data_read_buffer_size)), $offset, $atomHierarchy, $this->ParseAllPossibleAtoms);
$offset += $atomsize;
$atomcounter++;
@@ -799,9 +799,9 @@ public function QuicktimeParseAtom($atomname, $atomsize, $atom_data, $baseoffset
//$FrameRateCalculatorArray = array();
$frames_count = 0;
$max_stts_entries_to_scan = min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']);
$max_stts_entries_to_scan = ($info['php_memory_limit'] ? min(floor($this->getid3->memory_limit / 10000), $atom_structure['number_entries']) : $atom_structure['number_entries']);
if ($max_stts_entries_to_scan < $atom_structure['number_entries']) {
$info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($this->getid3->memory_limit / 1048576).'MB).';
$info['warning'][] = 'QuickTime atom "stts" has '.$atom_structure['number_entries'].' but only scanning the first '.$max_stts_entries_to_scan.' entries due to limited PHP memory available ('.floor($atom_structure['number_entries'] / 1048576).'MB).';
}
for ($i = 0; $i < $max_stts_entries_to_scan; $i++) {
$atom_structure['time_to_sample_table'][$i]['sample_count'] = getid3_lib::BigEndian2Int(substr($atom_data, $sttsEntriesDataOffset, 4));

0 comments on commit a99b19f

Please sign in to comment.
You can’t perform that action at this time.