|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-03-03 05:01 UTC] salsi at icosaedro dot it
-Summary: zlib.compress fails on empty data
+Summary: zlib.deflate fails on empty data
[2016-03-03 05:01 UTC] salsi at icosaedro dot it
[2016-07-02 13:43 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2016-07-02 13:43 UTC] cmb@php.net
[2021-07-27 11:57 UTC] cmb@php.net
-Status: Verified
+Status: Duplicate
-Assigned To:
+Assigned To: cmb
[2021-07-27 11:57 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 11:00:02 2025 UTC |
Description: ------------ The zlib.compress filter writes nothing when the data to write are empty. Instead, the DEFLATE algo (RFC 1950) requires to write at least one last block of data, as the gzdeflate() function correctly does: gzdeflate("") --> "\x03\x00" The result is that the written file cannot be decoded with gzinflate() withour error. In fact gzinflate() correctly recognizes the empty string as invalid DEFLATE format (there must be at least one block of compressed data with the first but set to mark the last block of data). The following test code, perfectly working as expected under PHP 5.6.3, fails as stated above on PHP 7. Test script: --------------- <?php /* * The zlib.compress filter writes nothing if the data to compress are the empty * string. * PHP 7.1.0-dev from git 2016-01-17 */ // Set a safe test environment: error_reporting(-1); // maps errors to ErrorException: function my_error_handler($errno, $message) { throw new ErrorException($message); } set_error_handler("my_error_handler"); /** * @param string $plain */ function test($plain) { echo "Now testing with $plain:\n"; $fn = "test"; $f = fopen($fn, "wb"); stream_filter_append($f, 'zlib.deflate', STREAM_FILTER_WRITE); fwrite($f, $plain); fclose($f); $compressed = file_get_contents($fn); echo "compressed: ", rawurlencode($compressed), "\n"; $plain2 = gzinflate($compressed); echo "decompressed: ", rawurlencode($plain2), "\n"; } echo "gzdeflate(\"\"): ", rawurlencode(gzdeflate("")), "\n"; test("abc"); // ok test(""); // no data written, error on gzinflate() ?> Expected result: ---------------- gzdeflate(""): %03%00 Now testing with abc: compressed: KLJ%06%00 decompressed: abc Now testing with : compressed: %03%00 decompressed: (this actually is the output of PHP 5.6.3) Actual result: -------------- gzdeflate(""): %03%00 Now testing with abc: compressed: KLJ%06%00 decompressed: abc Now testing with : compressed: PHP Fatal error: Uncaught ErrorException: gzinflate(): data error in /home/salsi/src/phplint/bugs/bug-zlib-compress-filter-on-empty-string.php:12