#34821 [Opn]: zlib encoders fail on widely varying binary data

From: Date: Tue, 11 Oct 2005 15:38:00 +0000
Subject: #34821 [Opn]: zlib encoders fail on widely varying binary data
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86415@lists.php.net to get a copy of this message
ID: 34821 Updated by: mike@php.net Reported By: mike@php.net Status: Open Bug Type: Zlib Related Operating System: * -PHP Version: 4, 5, 6? +PHP Version: * New Comment: A possible fix would be to raise the size of the memory allocated by default, e.g. adding 1% to the length of the incoming data instead of 0.1% additionally to some "safe" padding bytes. Previous Comments: ------------------------------------------------------------------------ [2005-10-10 22:50:22] mike@php.net Description: ------------ Probably an edge case, but so nobody could claim I didn't report it ;) It starts to fail with ~200k+. Reproduce code: --------------- <?php $j = 200000; $s = ''; srand(time()); for ($i = 0; $i < $j; ++$i) { $s .= chr(rand(0,255)); } gzencode($s); // fails with buffer error $r = array(); echo "\nCharcode stats:\n"; for ($i = 0; $i < $j; ++$i) { $x = ord($s{$i}); $r[$x] = isset($r[$x]) ? $r[$x]+1 : 1; } asort($r); printf("MIN: %d -- AVG: %d -- MAX: %d\n", current($r), array_sum($r)/count($r), end($r)); ?> Expected result: ---------------- No error Actual result: -------------- Warning: gzencode(): buffer error in C:\Webserver\mike\zone\gzencode.php on line 10 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34821&edit=1

« previous php.bugs (#86415) next »