Skip to content

Commit 49e181e

Browse files
author
Greg Beaver
committed
fix Bug #43793: zlib filter is unable to auto-detect gzip/zlib file headers
1 parent 3a6acb4 commit 49e181e

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
zlib.inflate of gzip-encoded stream
3+
--SKIPIF--
4+
<?php if (!extension_loaded("zlib")) print "skip"; ?>
5+
--FILE--
6+
<?php /* $Id$ */
7+
8+
$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
9+
fwrite($a, "This is quite the thing ain't it\n");
10+
fclose($a);
11+
12+
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
13+
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
14+
echo fread($fp, 2000);
15+
fclose($fp);
16+
echo "1\n";
17+
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
18+
// zlib format
19+
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
20+
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+16));
21+
echo "2\n";
22+
echo fread($fp, 2000);
23+
fclose($fp);
24+
// auto-detect
25+
$fp = fopen(dirname(__FILE__) . '/test.txt.gz', 'r');
26+
stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ, array('window' => 15+32));
27+
echo "3\n";
28+
echo fread($fp, 2000);
29+
fclose($fp);
30+
31+
?>
32+
--CLEAN--
33+
<?php
34+
@unlink(dirname(__FILE__) . '/test.txt.gz');
35+
?>
36+
--EXPECT--
37+
1
38+
2
39+
This is quite the thing ain't it
40+
3
41+
This is quite the thing ain't it

ext/zlib/zlib_filter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
323323
/* log-2 base of history window (9 - 15) */
324324
SEPARATE_ZVAL(tmpzval);
325325
convert_to_long_ex(tmpzval);
326-
if (Z_LVAL_PP(tmpzval) < -MAX_WBITS || Z_LVAL_PP(tmpzval) > MAX_WBITS) {
326+
if (Z_LVAL_PP(tmpzval) < -MAX_WBITS || Z_LVAL_PP(tmpzval) > MAX_WBITS + 32) {
327327
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL_PP(tmpzval));
328328
} else {
329329
windowBits = Z_LVAL_PP(tmpzval);

0 commit comments

Comments
 (0)