Fatal Error in module.graphic.jpg.php

Locked
Michel-Ange
User
Posts: 1
Joined: Thu Jan 31, 2013 9:36 am
Are you a spambot?: no

Fatal Error in module.graphic.jpg.php

Post by Michel-Ange » Thu Jan 31, 2013 9:49 am

Version : 1.9.3-20111213

When trying to read one 45mo file infos on one server which has 32M memory limit, I got this :

`Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 49478365 bytes) in [....]/getid3/module.graphic.jpg.php on line 34

After a look at the code, I saw that this line 34 do that :

Code: Select all

	list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($this->getid3->fp, $info['filesize']), $imageinfo);
So, here, we basically need the width, the height and the type, which can be obtained by the PHP function getimagesize().

So I went to GetDataImageSize() to see what's the magical behind :

Code: Select all

	static function GetDataImageSize($imgData, &$imageinfo) {
		static $tempdir = '';
		if (empty($tempdir)) {
			// yes this is ugly, feel free to suggest a better way
			require_once(dirname(__FILE__).'/getid3.php');
			$getid3_temp = new getID3();
			$tempdir = $getid3_temp->tempdir;
			unset($getid3_temp);
		}
		$GetDataImageSize = false;
		if ($tempfilename = tempnam($tempdir, 'gI3')) {
			if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) {
				fwrite($tmp, $imgData);
				fclose($tmp);
				$GetDataImageSize = @GetImageSize($tempfilename, $imageinfo);
			}
			unlink($tempfilename);
		}
		return $GetDataImageSize;
	}

It looks like it copies the file and then reads the size with "@GetImageSize" (which should be written lowercase btw.)
What's the purpose of the copy ?
It uses just memory for nothing.

What I suggest :
In module.graphic.jpg.php, line 34, replace :

Code: Select all

list($width, $height, $type) = getid3_lib::GetDataImageSize(fread($this->getid3->fp, $info['filesize']), $imageinfo);
by :

Code: Select all

list($width, $height, $type) = getimagesize($info['filenamepath'], $imageinfo);

James Heinrich
getID3() v1 developer
Posts: 1457
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: Fatal Error in module.graphic.jpg.php

Post by James Heinrich » Thu Jan 31, 2013 2:23 pm

I'm sure there was probably a good reason when the code was written... but I can't think of what it would be :)

Fix accepted, will be included in v1.9.5

Locked