summaryrefslogtreecommitdiff
path: root/ext/zlib
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-04-06 14:37:49 +0200
committerOndřej Surý <ondrej@sury.org>2012-04-06 14:37:49 +0200
commit7b10b0041aa63c6f8990ceb3ccc190bdd9eea2b9 (patch)
tree01edb9389d7b7f6b277a57e2bce1d05f9748d609 /ext/zlib
parent096b2f823b2273e3ee707b3805feb78d1e4be61d (diff)
downloadphp-7b10b0041aa63c6f8990ceb3ccc190bdd9eea2b9.tar.gz
Imported Upstream version 5.4.1~rc1upstream/5.4.1_rc1
Diffstat (limited to 'ext/zlib')
-rw-r--r--ext/zlib/config.w322
-rw-r--r--ext/zlib/config0.m42
-rw-r--r--ext/zlib/php_zlib.h3
-rw-r--r--ext/zlib/tests/001.phpt2
-rw-r--r--ext/zlib/tests/002.phpt2
-rw-r--r--ext/zlib/tests/bug60761.phpt45
-rw-r--r--ext/zlib/tests/bug61139.phpt14
-rw-r--r--ext/zlib/tests/bug61287.phpt24
-rw-r--r--ext/zlib/tests/gzfilegzreadfile.phpt2
-rw-r--r--ext/zlib/tests/zlib_filter_deflate.phpt2
-rw-r--r--ext/zlib/tests/zlib_filter_inflate.phpt2
-rw-r--r--ext/zlib/tests/zlib_filter_inflate2.phpt2
-rw-r--r--ext/zlib/zlib.c14
-rw-r--r--ext/zlib/zlib_filter.c2
-rw-r--r--ext/zlib/zlib_fopen_wrapper.c27
15 files changed, 102 insertions, 43 deletions
diff --git a/ext/zlib/config.w32 b/ext/zlib/config.w32
index 5e51cfed9..000b1ccab 100644
--- a/ext/zlib/config.w32
+++ b/ext/zlib/config.w32
@@ -1,4 +1,4 @@
-// $Id: config.w32 261512 2008-06-22 21:55:59Z pajoye $
+// $Id$
// vim:ft=javascript
ARG_ENABLE("zlib", "ZLIB support", "yes");
diff --git a/ext/zlib/config0.m4 b/ext/zlib/config0.m4
index ba792ea74..25c7f4f42 100644
--- a/ext/zlib/config0.m4
+++ b/ext/zlib/config0.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config0.m4 299980 2010-05-31 10:29:43Z mike $
+dnl $Id$
dnl
PHP_ARG_WITH(zlib,for ZLIB support,
diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h
index c301e4376..3d8c90cbf 100644
--- a/ext/zlib/php_zlib.h
+++ b/ext/zlib/php_zlib.h
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_zlib.h 321634 2012-01-01 13:15:04Z felipe $ */
+/* $Id$ */
#ifndef PHP_ZLIB_H
#define PHP_ZLIB_H
@@ -65,6 +65,7 @@ extern zend_module_entry php_zlib_module_entry;
#define phpext_zlib_ptr zlib_module_ptr
#ifdef ZTS
+# include "TSRM.h"
# define ZLIBG(v) TSRMG(zlib_globals_id, zend_zlib_globals *, v)
#else
# define ZLIBG(v) (zlib_globals.v)
diff --git a/ext/zlib/tests/001.phpt b/ext/zlib/tests/001.phpt
index 404e825c2..0c2ca28c7 100644
--- a/ext/zlib/tests/001.phpt
+++ b/ext/zlib/tests/001.phpt
@@ -3,7 +3,7 @@ gzdeflate()/gzinflate()
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
-<?php /* $Id: 001.phpt 316410 2011-09-08 10:20:38Z pajoye $ */
+<?php /* $Id$ */
$original = str_repeat("hallo php",4096);
$packed=gzdeflate($original);
echo strlen($packed)." ".strlen($original)."\n";
diff --git a/ext/zlib/tests/002.phpt b/ext/zlib/tests/002.phpt
index b40f1ff36..9844a1b93 100644
--- a/ext/zlib/tests/002.phpt
+++ b/ext/zlib/tests/002.phpt
@@ -3,7 +3,7 @@ gzcompress()/gzuncompress()
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
-<?php /* $Id: 002.phpt 242949 2007-09-26 15:44:16Z cvs2svn $ */
+<?php /* $Id$ */
$original = str_repeat("hallo php",4096);
$packed=gzcompress($original);
echo strlen($packed)." ".strlen($original)."\n";
diff --git a/ext/zlib/tests/bug60761.phpt b/ext/zlib/tests/bug60761.phpt
index 823173ec2..1e9fe69a0 100644
--- a/ext/zlib/tests/bug60761.phpt
+++ b/ext/zlib/tests/bug60761.phpt
@@ -1,34 +1,53 @@
--TEST--
-checks zlib compression size is always the same no matter how many times its run
+checks zlib compression output size is always the same
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
+--CGI--
+1
--FILE--
<?php
-ob_start();
-phpinfo();
-$html = ob_get_clean();
+// the INI directives from bug #60761 report
+ini_set('zlib.output_compression', '4096');
+ini_set('zlib.output_compression_level', '9');
+
+// try to duplicate the original bug by running this as a CGI
+// test using ob_start and zlib.output_compression(or ob_gzhandler)
+// so it follows more of the original code-path than just calling
+// gzcompress on CLI or CGI
$lens = array();
-for ( $i=0 ; $i < 200 ; $i++ ) {
- //zlib.output_compression = On
- //zlib.output_compression_level = 9
- $compressed = gzcompress($html, 9);
-
- $len = strlen($compressed);
+for ( $i=0 ; $i < 100 ; $i++ ) {
+
+ // can't use ob_gzhandler with zlib.output_compression
+ ob_start();//"ob_gzhandler");
+ phpinfo();
+ $html = ob_get_clean();
+
+ $len = strlen($html);
$lens[$len] = $len;
}
$lens = array_values($lens);
-echo "Compressed lengths\n";
-var_dump($lens);
+echo "Compressed Lengths\n";
+
+// pass == only ONE length for all iterations
+// (length didn't change during run)
+//
+// hard to anticipate what 'correct' length should be since
+// return value of phpinfo() will vary between installations...
+// just check that there is only one length
+//
+var_dump($lens); // show lengths to help triage in case of failure
+
+// expected headers since its CGI
?>
--EXPECTF--
-Compressed lengths
+%s
array(1) {
[0]=>
int(%d)
diff --git a/ext/zlib/tests/bug61139.phpt b/ext/zlib/tests/bug61139.phpt
new file mode 100644
index 000000000..eaca00369
--- /dev/null
+++ b/ext/zlib/tests/bug61139.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #61139 (gzopen leaks when specifying invalid mode)
+--SKIPIF--
+<?php
+if (!extension_loaded('zlib')) {
+ die('skip - zlib extension not loaded');
+}
+?>
+--FILE--
+<?php
+
+gzopen('someFile', 'c');
+--EXPECTF--
+Warning: gzopen(): gzopen failed in %s on line %d
diff --git a/ext/zlib/tests/bug61287.phpt b/ext/zlib/tests/bug61287.phpt
new file mode 100644
index 000000000..769446a8c
--- /dev/null
+++ b/ext/zlib/tests/bug61287.phpt
@@ -0,0 +1,24 @@
+--TEST--
+bug #61287 - inflate needs the terminating null byte
+--SKIPIF--
+<?php extension_loaded("zlib") or die("SKIP need zlib");
+--FILE--
+<?php
+$array = array(
+ 'region_id' => 1,
+ 'discipline' => 23,
+ 'degrees' => array(),
+ 'country_id' => 27
+);
+
+$serialized = serialize($array);
+
+$deflated = gzdeflate($serialized, 9);
+$inflated = gzinflate($deflated);
+
+echo strlen($inflated),"\n";
+?>
+Done
+--EXPECT--
+92
+Done
diff --git a/ext/zlib/tests/gzfilegzreadfile.phpt b/ext/zlib/tests/gzfilegzreadfile.phpt
index f8550c2d1..2d6843ddd 100644
--- a/ext/zlib/tests/gzfilegzreadfile.phpt
+++ b/ext/zlib/tests/gzfilegzreadfile.phpt
@@ -1,7 +1,7 @@
--TEST--
gzfile(), gzreadfile()
--SKIPIF--
-<?php /* $Id: gzfilegzreadfile.phpt 316410 2011-09-08 10:20:38Z pajoye $ */
+<?php /* $Id$ */
if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
diff --git a/ext/zlib/tests/zlib_filter_deflate.phpt b/ext/zlib/tests/zlib_filter_deflate.phpt
index c31702048..1811779f0 100644
--- a/ext/zlib/tests/zlib_filter_deflate.phpt
+++ b/ext/zlib/tests/zlib_filter_deflate.phpt
@@ -3,7 +3,7 @@ zlib.deflate (with convert.base64-encode)
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
-<?php /* $Id: zlib_filter_deflate.phpt 201145 2005-11-24 04:37:47Z pollita $ */
+<?php /* $Id$ */
$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.';
$fp = fopen('php://stdout', 'w');
diff --git a/ext/zlib/tests/zlib_filter_inflate.phpt b/ext/zlib/tests/zlib_filter_inflate.phpt
index 0a5836e3c..026f192a6 100644
--- a/ext/zlib/tests/zlib_filter_inflate.phpt
+++ b/ext/zlib/tests/zlib_filter_inflate.phpt
@@ -3,7 +3,7 @@ zlib.inflate (with convert.base64-decode)
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
-<?php /* $Id: zlib_filter_inflate.phpt 201145 2005-11-24 04:37:47Z pollita $ */
+<?php /* $Id$ */
$text = 'HctBDoAgDETRq8zOjfEeHKOGATG0TRpC4u1Vdn/xX4IoxkVMxgP1zA4vkJVhULk9UGkM6TvSNolmxUNlNLePVQ45O3eINf0fsQxtCxwv';
$fp = fopen('php://stdout', 'w');
diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt
index 53f99cf16..a2099b6f7 100644
--- a/ext/zlib/tests/zlib_filter_inflate2.phpt
+++ b/ext/zlib/tests/zlib_filter_inflate2.phpt
@@ -3,7 +3,7 @@ zlib.inflate of gzip-encoded stream
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
-<?php /* $Id: zlib_filter_inflate2.phpt 299980 2010-05-31 10:29:43Z mike $ */
+<?php /* $Id$ */
$a = gzopen(dirname(__FILE__) . '/test.txt.gz', 'w');
fwrite($a, b"This is quite the thing ain't it\n");
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 387cf017d..d472573b7 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zlib.c 321634 2012-01-01 13:15:04Z felipe $ */
+/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -400,7 +400,7 @@ retry_raw_inflate:
status = inflateInit2(&Z, encoding);
if (Z_OK == status) {
Z.next_in = (Bytef *) in_buf;
- Z.avail_in = in_len;
+ Z.avail_in = in_len + 1; /* NOTE: data must be zero terminated */
switch (status = php_zlib_inflate_rounds(&Z, max_len, out_buf, out_len)) {
case Z_STREAM_END:
@@ -938,7 +938,6 @@ static PHP_MINIT_FUNCTION(zlib)
REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_CS|CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
- ZLIBG(ob_gzhandler) = NULL;
return SUCCESS;
}
/* }}} */
@@ -989,6 +988,13 @@ static PHP_MINFO_FUNCTION(zlib)
}
/* }}} */
+/* {{{ ZEND_MODULE_GLOBALS_CTOR */
+static ZEND_MODULE_GLOBALS_CTOR_D(zlib)
+{
+ zlib_globals->ob_gzhandler = NULL;
+}
+/* }}} */
+
/* {{{ php_zlib_module_entry */
zend_module_entry php_zlib_module_entry = {
STANDARD_MODULE_HEADER,
@@ -1001,7 +1007,7 @@ zend_module_entry php_zlib_module_entry = {
PHP_MINFO(zlib),
"2.0",
PHP_MODULE_GLOBALS(zlib),
- NULL,
+ ZEND_MODULE_GLOBALS_CTOR_N(zlib),
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c
index e6b235c7b..b9c55d330 100644
--- a/ext/zlib/zlib_filter.c
+++ b/ext/zlib/zlib_filter.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zlib_filter.c 321634 2012-01-01 13:15:04Z felipe $ */
+/* $Id$ */
#include "php.h"
#include "php_zlib.h"
diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c
index e38cf289a..039e3d1aa 100644
--- a/ext/zlib/zlib_fopen_wrapper.c
+++ b/ext/zlib/zlib_fopen_wrapper.c
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zlib_fopen_wrapper.c 321634 2012-01-01 13:15:04Z felipe $ */
+/* $Id$ */
#define _GNU_SOURCE
@@ -109,7 +109,7 @@ php_stream_ops php_stream_gzio_ops = {
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options,
char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
- struct php_gz_stream_data_t *self = {0};
+ struct php_gz_stream_data_t *self;
php_stream *stream = NULL, *innerstream = NULL;
/* sanity check the stream: it can be either read-only or write-only */
@@ -120,8 +120,6 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mod
return NULL;
}
- self = emalloc(sizeof(*self));
-
if (strncasecmp("compress.zlib://", path, 16) == 0) {
path += 16;
} else if (strncasecmp("zlib:", path, 5) == 0) {
@@ -134,32 +132,29 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mod
int fd;
if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) {
- self->gz_file = gzdopen(dup(fd), mode);
+ self = emalloc(sizeof(*self));
self->stream = innerstream;
- if (self->gz_file) {
+ self->gz_file = gzdopen(dup(fd), mode);
+
+ if (self->gz_file) {
stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode);
if (stream) {
stream->flags |= PHP_STREAM_FLAG_NO_BUFFER;
return stream;
}
+
gzclose(self->gz_file);
}
+
+ efree(self);
if (options & REPORT_ERRORS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "gzopen failed");
}
- } else if (innerstream) {
- php_stream_close(innerstream);
}
- }
- if (stream) {
- php_stream_close(stream);
- }
-
- if (self) {
- efree(self);
+ php_stream_close(innerstream);
}
-
+
return NULL;
}