php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43400 Deflate filter doesn't compress all data
Submitted: 2007-11-25 19:02 UTC Modified: 2008-11-03 01:00 UTC
From: witekfl at poczta dot onet dot pl Assigned:
Status: No Feedback Package: Zlib related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-11-25 19:02 UTC] witekfl at poczta dot onet dot pl
Description:
------------
The deflate filter doesn't compress all data.
The decompressed data is 1721662 bytes long.

Reproduce code:
---------------
<?php
$f = fopen("http://republika.pl/rkd/data.bz2", "rb");
$data = '';
while (!feof($f)) {
        $data .= fread($f, 32768);
}
fclose($f);
$text = bzdecompress($data);

$f3 = fopen("data.html.deflate", "wb");
stream_filter_append($f3, 'zlib.deflate', STREAM_FILTER_WRITE);
fwrite($f3, $text); fclose($f3);

$f5 = fopen("data.html.deflate", "rb");
stream_filter_append($f5, 'zlib.inflate', STREAM_FILTER_READ);
$text_deflate = ''; while (!feof($f5)) { $text_deflate .= fread($f5, 32768); } fclose($f5);

printf("original = %d, deflate = %d\n", strlen($text), strlen($text_deflate));
?>


Expected result:
----------------
original = 1721662, deflate = 1721662


Actual result:
--------------
original = 1721662, deflate = 546816


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-02 18:49 UTC] witekfl at poczta dot onet dot pl
This patch solves the problem:
--- php-5.2.2/ext/zlib/zlib_filter.c.old        2007-05-07 19:42:29.000000000 +0
200
+++ php-5.2.2/ext/zlib/zlib_filter.c    2007-05-07 21:35:25.000000000 +0200
@@ -100,11 +100,6 @@
                        consumed += desired;
                        bin += desired;
 
-                       if (!desired) {
-                               flags |= PSFS_FLAG_FLUSH_CLOSE;
-                               break;
-                       }
-
                        if (data->strm.avail_out < data->outbuf_len) {
                                php_stream_bucket *out_bucket;
                                size_t bucketlen = data->outbuf_len - data->strm
.avail_out;
@@ -213,11 +208,6 @@
                        consumed += desired;
                        bin += desired;
 
-                       if (!desired) {
-                               flags |= PSFS_FLAG_FLUSH_CLOSE;
-                               break;
-                       }
-
                        if (data->strm.avail_out < data->outbuf_len) {
                                php_stream_bucket *out_bucket;
                                size_t bucketlen = data->outbuf_len - data->strm
.avail_out;
 [2008-10-26 23:42 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-10-29 18:41 UTC] witekfl at poczta dot onet dot pl
It works! Thank you!
 [2008-11-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC