|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2019-07-23 12:05 UTC] albertcasademont at gmail dot com
[2019-07-23 12:06 UTC] albertcasademont at gmail dot com
[2019-07-29 15:35 UTC] nikic@php.net
[2019-07-29 15:35 UTC] nikic@php.net
-Status: Open
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
Description: ------------ When calling stream_get_contents() with a fixed length buffer, the memory allocated for that buffer is not freed even though the actual data might be much shorter than the allocated buffer. This can potentially crash the script just after a couple of stream_get_contents() calls due to memory issues. If we don't specify a fixed lenght buffer, php will correctly reallocate the string to the exact amount of data read. This would also be the expected thing to do even if we fix the buffer length. Test script: --------------- <?php $f = tmpfile(); fwrite($f, '.'); $chunks = array(); for ($i = 0; $i < 1000; ++$i) { rewind($f); $chunks[] = stream_get_contents($f, 1000000); } var_dump(count($chunks)); Expected result: ---------------- int(1000) Actual result: -------------- Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 1003520 bytes) in /in/HP2U9 on line 9