|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43793 zlib filter is unable to auto-detect gzip/zlib file headers
Submitted: 2008-01-09 06:38 UTC Modified: 2008-01-09 07:09 UTC
From: Assigned: cellog (profile)
Status: Closed Package: Streams related
PHP Version: 5.2.5 OS: n/a
Private report: No CVE-ID: None
 [2008-01-09 06:38 UTC]
according to the zlib documentation for inflateInit2() in zlib.h (online copy at

windowBits can also be greater than 15 for optional gzip decoding. Add
32 to windowBits to enable zlib and gzip decoding with automatic header
detection, or add 16 to decode only the gzip format (the zlib format will return a Z_DATA_ERROR)

zlib.inflate filter's filterparams only accepts window size of 15, but should accept up to 15+32 according to these docs.

Reproduce code:
<?php /* $Id: zlib_filter_inflate.phpt,v 2005/11/24 04:37:47 pollita Exp $ */

$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
fwrite($a, "This is quite the thing ain't it\n");

$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
echo fread($fp, 2000);
echo "1\n";
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
// zlib format
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+16));
echo "2\n";
echo fread($fp, 2000);
// auto-detect
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+32));
echo "3\n";
echo fread($fp, 2000);


Expected result:
This is quite the thing ain't it
This is quite the thing ain't it

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-09 07:09 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 07:01:25 2019 UTC