View Issue Details

IDProjectCategoryView StatusLast Update
0011720mantisbtattachmentspublic2010-09-19 03:11
Reporterhallids Assigned Todhx  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
Product Version1.2.0 
Summary0011720: file_download.php running out of memory
Description

When downloading an attachment, file_download.php is running out of memory, on any size file. Only occurs on files uploaded with earlier version of Mantis. (Not sure which earlier version of Mantis. My previous version was 1.1.4.)

The file download completes ok but the file contents is appended with a PHP out-of-memory error, for example

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 524289 bytes) in /var/www/example.com/htdocs/mantisbt-1.2.0/file_download.php on line 209

Steps To Reproduce

Open a ticket with a download added in an earlier version of Mantis. You'll need the PHP ini variable 'display_errors' set to be ON. Download the attachment (if it was a text file you will be able to see the appended error message).

Additional Information

I have fixed this problem in my copy by changing file_download.php line 210

from
if ( $buffer === false ) {

to
if ( !$buffer ) {

It seems like file_get_contents() is returning 0 (zero) instead of boolean false in some cases which is causing an infinite loop.

My PHP version is 5.2.5

TagsNo tags attached.
Attached Files
file_download.php.patch (958 bytes)   
*** file_download.orig.php	2010-03-29 09:59:29.000000000 +1030
--- file_download.php	2010-03-29 10:51:48.000000000 +1030
***************
*** 207,213 ****
  			@set_time_limit(60*60); //reset time limit to 60 min - should be enough for 1 MB chunk
  		}
          $buffer = file_get_contents($filename, 0, null, $offset, ( ($maxlength > 0 && $maxlength < $chunksize) ? $maxlength : $chunksize ) );
!         if ( $buffer === false ) {
  			if( $maxlength > 0 ) {
  				$buffer = file_get_contents($filename, 0, null, $offset, $maxlength );
  			} else {
--- 207,213 ----
  			@set_time_limit(60*60); //reset time limit to 60 min - should be enough for 1 MB chunk
  		}
          $buffer = file_get_contents($filename, 0, null, $offset, ( ($maxlength > 0 && $maxlength < $chunksize) ? $maxlength : $chunksize ) );
!         if ( !$buffer ) {
  			if( $maxlength > 0 ) {
  				$buffer = file_get_contents($filename, 0, null, $offset, $maxlength );
  			} else {
file_download.php.patch (958 bytes)   

Relationships

duplicate of 0011362 closeddhx Picture dowload fails wit exhausted memory error with firefox 3.5.7 but not with IE8 

Activities

hallids

hallids

2010-03-28 19:51

reporter   ~0024913

Apologies, should have said, this is occurring in Mantis version 1.2.0

System is Red Hat Linux 2.6.22.19