note 110817 added to function.gzinflate
| From: | akniep at rayo dot info | Date: | Tue, 11 Dec 2012 15:11:42 +0000 |
| Subject: | note 110817 added to function.gzinflate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192465@lists.php.net to get a copy of this message | ||
Take care when using the optional second parameter $length!
In our tests -at least in certain situations- we were unable to determine the actual use of this
parameter, plus, it lead to the script either being unable to inflate compressed data or crash due
to memory-problems.
Example:
When trying to inflate the compressed data from a website, we were literally unable to find a value
(other than 0) for $length in order to make gzinflate work... while without the second parameter (or
setting it to 0) gzinflate worked like a charm:
Test-URL: http://www.jumptags.com/topic/kreiskolbenmotor/
Deflated Content-Length: 4150
Inflated Content-Length: 10870
<?php
// -----------------------------------------------------------------------
// Test 1 works without problems. Memory peak usage: Before inflating: 24.787 kB; after: 24.844 kB.
gzinflate( substr($deflated_body, 10) );
// -----------------------------------------------------------------------
// ALL three of the following tests failed with a warning. Memory peak usage: Before inflating:
24.787 kB; after: 298.262 kB.
gzinflate( substr($deflated_body, 10), 200 * strlen($deflated_body) );
gzinflate( substr($deflated_body, 10), 32768 * strlen($deflated_body) );
gzinflate( substr($deflated_body, 10), 11000 );
gzinflate( substr($deflated_body, 10), 280000000 ); // the PHP memory limit was set to 300MB
(memory_limit=300M)
=>
Warning: gzinflate() [function.gzinflate]: insufficient memory in [...]
// -----------------------------------------------------------------------
// The last test failed with a fatal error. Memory peak usage: Before inflating: 24.787 kB; after: ?
(> 300M).
gzinflate( substr($deflated_body, 10), 300000000 ); // the PHP memory limit was set to 300MB
(memory_limit=300M)
=>
Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 300000000 bytes)
in
?>
In short: We were unable to determine the actual use of the second parameter in certain situations.
Be careful with using the second parameter $length!
----
Server IP: 212.124.37.9
Probable Submitter: 87.149.162.111
----
Manual Page -- http://php.net/manual/en/function.gzinflate.php
Edit -- https://master.php.net/note/edit/110817
Del: integrated -- https://master.php.net/note/delete/110817/integrated
Del: useless -- https://master.php.net/note/delete/110817/useless
Del: bad code -- https://master.php.net/note/delete/110817/bad+code
Del: spam -- https://master.php.net/note/delete/110817/spam
Del: non-english -- https://master.php.net/note/delete/110817/non-english
Del: in docs -- https://master.php.net/note/delete/110817/in+docs
Del: other reasons-- https://master.php.net/note/delete/110817
Reject -- https://master.php.net/note/reject/110817
Search -- https://master.php.net/manage/user-notes.php