On October 12, 2002 06:03 pm, Wez Furlong wrote:
> On 10/12/02, "Ilia A." <[EMAIL PROTECTED]> wrote:
> > #0  0x403cd271 in ?? ()
> > #1  0x8171922 in zif_fgets (ht=2, return_value=0x83c843c, this_ptr=0x0,
> > return_value_used=0) at /home/rei/PHP_CVS/php4/ext/standard/file.c:1271
> > #2  0x823faa2 in execute (op_array=0x83d498c) at
> > /home/rei/PHP_CVS/php4/Zend/zend_execute.c:1597
> > #3  0x822c9e4 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
> > at /home/rei/PHP_CVS/php4/Zend/zend.c:839
> > #4  0x81f2d81 in php_execute_script (primary_file=0xbffff6b0) at
> > /home/rei/PHP_CVS/php4/main/main.c:1542
> > #5  0x8250b47 in main (argc=2, argv=0xbffff734) at
> > /home/rei/PHP_CVS/php4/sapi/cli/php_cli.c:695
> > #6  0x403bdf5c in ?? ()
>
> That bt looks like it's missing some symbols.

True, I analyzed it with gdb, and it dies inside the emalloc() code because it 
is unable to allocate that much memory, it even goes as far as to give me a 
helpful message saying it cannot allocate memory. This all done by emalloc() 
function so that is all intentional. The core dump is there only because 
emalloc() dumps core if php is compiled with --enable-debug, without that 
flag it would just exit.

It seems that the older version of PHP I used to test this one did not provide 
the unable to emalloc message and just exited silently. Hence my faulty 
assumption that it had worked properly. Wez is absolutely correct in saying 
that the behaviour had not changed and this 'issue' was not introduced 
recently or is a new problem.

I still find it unusual that PHP would allocate memory solely based on user 
request via fgets/fread regardless of any other factors. For example opening 
a static 4 meg file should not cause the script to terminate if a user does
fread($fp, 1000000000);. This can be prevented using a simple check that would 
limit to allocation of memory to the size of the file being opened. For 
dynamic streams the solution is more complex because we do not know how much 
data is really there. However, we can add a fairly safe limit of 10 megs, if 
there trully is more then 10 megs of data then we would then reallocate 
another 10 megs and so on until all data is either read or we trully run out 
of memory. Doing a realloc() every 10 megs would add very little overhead and 
prevent unnecessary script terminations.

Ilia

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to