cellog Sat Oct 11 19:14:08 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src NEWS
/php-src/ext/zlib zlib_filter.c
/php-src/ext/bz2 bz2_filter.c
Log:
fix Bug #46026: bz2.decompress/zlib.inflate filter tries to decompress after
end of stream
[DOC] add concatenation option to bz2.decompress stream filter
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.342&r2=1.2027.2.547.2.965.2.343&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.342
php-src/NEWS:1.2027.2.547.2.965.2.343
--- php-src/NEWS:1.2027.2.547.2.965.2.342 Thu Oct 9 00:51:10 2008
+++ php-src/NEWS Sat Oct 11 19:14:08 2008
@@ -9,7 +9,9 @@
- Changed openssl info to show the shared library version number. (Scott)
- Added ability to send user defined HTTP headers with SOAP request.
- (Brain J.France, Dmitry)
+ (Brian J.France, Dmitry)
+- Added concatenation option to bz2.decompress stream filter.
+ (Keisial at gmail dot com, Greg)
- Fixed bug causing the algorithm parameter of mhash() to be modified. (Scott)
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib_filter.c?r1=1.6.2.2.2.4.2.7&r2=1.6.2.2.2.4.2.8&diff_format=u
Index: php-src/ext/zlib/zlib_filter.c
diff -u php-src/ext/zlib/zlib_filter.c:1.6.2.2.2.4.2.7
php-src/ext/zlib/zlib_filter.c:1.6.2.2.2.4.2.8
--- php-src/ext/zlib/zlib_filter.c:1.6.2.2.2.4.2.7 Tue Feb 12 23:28:05 2008
+++ php-src/ext/zlib/zlib_filter.c Sat Oct 11 19:14:08 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zlib_filter.c,v 1.6.2.2.2.4.2.7 2008/02/12 23:28:05 cellog Exp $ */
+/* $Id: zlib_filter.c,v 1.6.2.2.2.4.2.8 2008/10/11 19:14:08 cellog Exp $ */
#include "php.h"
#include "php_zlib.h"
@@ -31,6 +31,7 @@
size_t inbuf_len;
char *outbuf;
size_t outbuf_len;
+ zend_bool finished;
} php_zlib_filter_data;
/* }}} */
@@ -81,6 +82,12 @@
bucket = php_stream_bucket_make_writeable(buckets_in->head
TSRMLS_CC);
while (bin < bucket->buflen) {
+
+ if (data->finished) {
+ consumed += bucket->buflen;
+ break;
+ }
+
desired = bucket->buflen - bin;
if (desired > data->inbuf_len) {
desired = data->inbuf_len;
@@ -89,7 +96,10 @@
data->strm.avail_in = desired;
status = inflate(&(data->strm), flags &
PSFS_FLAG_FLUSH_CLOSE ? Z_FINISH : Z_SYNC_FLUSH);
- if (status != Z_OK && status != Z_STREAM_END) {
+ if (status == Z_STREAM_END) {
+ inflateEnd(&(data->strm));
+ data->finished = '\1';
+ } else if (status != Z_OK) {
/* Something bad happened */
php_stream_bucket_delref(bucket TSRMLS_CC);
return PSFS_ERR_FATAL;
@@ -117,7 +127,7 @@
php_stream_bucket_delref(bucket TSRMLS_CC);
}
- if (flags & PSFS_FLAG_FLUSH_CLOSE) {
+ if (!data->finished && flags & PSFS_FLAG_FLUSH_CLOSE) {
/* Spit it out! */
status = Z_OK;
while (status == Z_OK) {
@@ -145,7 +155,9 @@
{
if (thisfilter && thisfilter->abstract) {
php_zlib_filter_data *data = thisfilter->abstract;
- inflateEnd(&(data->strm));
+ if (!data->finished) {
+ inflateEnd(&(data->strm));
+ }
pefree(data->inbuf, data->persistent);
pefree(data->outbuf, data->persistent);
pefree(data, data->persistent);
@@ -329,6 +341,7 @@
}
/* RFC 1951 Inflate */
+ data->finished = '\0';
status = inflateInit2(&(data->strm), windowBits);
fops = &php_zlib_inflate_ops;
} else if (strcasecmp(filtername, "zlib.deflate") == 0) {
http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/bz2_filter.c?r1=1.3.2.2.2.5.2.4&r2=1.3.2.2.2.5.2.5&diff_format=u
Index: php-src/ext/bz2/bz2_filter.c
diff -u php-src/ext/bz2/bz2_filter.c:1.3.2.2.2.5.2.4
php-src/ext/bz2/bz2_filter.c:1.3.2.2.2.5.2.5
--- php-src/ext/bz2/bz2_filter.c:1.3.2.2.2.5.2.4 Sat Jan 12 22:03:32 2008
+++ php-src/ext/bz2/bz2_filter.c Sat Oct 11 19:14:08 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: bz2_filter.c,v 1.3.2.2.2.5.2.4 2008/01/12 22:03:32 cellog Exp $ */
+/* $Id: bz2_filter.c,v 1.3.2.2.2.5.2.5 2008/10/11 19:14:08 cellog Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -27,6 +27,12 @@
/* {{{ data structure */
+enum strm_status {
+ PHP_BZ2_UNITIALIZED,
+ PHP_BZ2_RUNNING,
+ PHP_BZ2_FINISHED
+};
+
typedef struct _php_bz2_filter_data {
int persistent;
bz_stream strm;
@@ -34,6 +40,11 @@
size_t inbuf_len;
char *outbuf;
size_t outbuf_len;
+
+ /* Decompress options */
+ enum strm_status status;
+ unsigned int small_footprint : 1;
+ unsigned int expect_concatenated : 1;
} php_bz2_filter_data;
/* }}} */
@@ -82,6 +93,21 @@
bucket = php_stream_bucket_make_writeable(buckets_in->head
TSRMLS_CC);
while (bin < bucket->buflen) {
+ if (data->status == PHP_BZ2_UNITIALIZED) {
+ status = BZ2_bzDecompressInit(streamp, 0,
data->small_footprint);
+
+ if (BZ_OK != status) {
+ return PSFS_ERR_FATAL;
+ }
+
+ data->status = PHP_BZ2_RUNNING;
+ }
+
+ if (data->status != PHP_BZ2_RUNNING) {
+ consumed += bucket->buflen;
+ break;
+ }
+
desired = bucket->buflen - bin;
if (desired > data->inbuf_len) {
desired = data->inbuf_len;
@@ -90,7 +116,15 @@
data->strm.avail_in = desired;
status = BZ2_bzDecompress(&(data->strm));
- if (status != BZ_OK && status != BZ_STREAM_END) {
+
+ if (status == BZ_STREAM_END) {
+ BZ2_bzDecompressEnd(&(data->strm));
+ if (data->expect_concatenated) {
+ data->status = PHP_BZ2_UNITIALIZED;
+ } else {
+ data->status = PHP_BZ2_FINISHED;
+ }
+ } else if (status != BZ_OK) {
/* Something bad happened */
php_stream_bucket_delref(bucket TSRMLS_CC);
return PSFS_ERR_FATAL;
@@ -115,10 +149,11 @@
return PSFS_PASS_ON;
}
}
+
php_stream_bucket_delref(bucket TSRMLS_CC);
}
- if (flags & PSFS_FLAG_FLUSH_CLOSE) {
+ if ((data->status == PHP_BZ2_RUNNING) && (flags &
PSFS_FLAG_FLUSH_CLOSE)) {
/* Spit it out! */
status = BZ_OK;
while (status == BZ_OK) {
@@ -148,7 +183,9 @@
{
if (thisfilter && thisfilter->abstract) {
php_bz2_filter_data *data = thisfilter->abstract;
- BZ2_bzDecompressEnd(&(data->strm));
+ if (data->status == PHP_BZ2_RUNNING) {
+ BZ2_bzDecompressEnd(&(data->strm));
+ }
pefree(data->inbuf, data->persistent);
pefree(data->outbuf, data->persistent);
pefree(data, data->persistent);
@@ -275,7 +312,7 @@
{
php_stream_filter_ops *fops = NULL;
php_bz2_filter_data *data;
- int status;
+ int status = BZ_OK;
/* Create this filter */
data = pecalloc(1, sizeof(php_bz2_filter_data), persistent);
@@ -307,12 +344,22 @@
}
if (strcasecmp(filtername, "bzip2.decompress") == 0) {
- int smallFootprint = 0;
+ data->small_footprint = 0;
+ data->expect_concatenated = 0;
if (filterparams) {
zval **tmpzval = NULL;
if (Z_TYPE_P(filterparams) == IS_ARRAY ||
Z_TYPE_P(filterparams) == IS_OBJECT) {
+
+ if (SUCCESS ==
zend_hash_find(HASH_OF(filterparams), "concatenated", sizeof("concatenated"),
(void **) &tmpzval) ) {
+ SEPARATE_ZVAL(tmpzval);
+ convert_to_boolean_ex(tmpzval);
+ data->expect_concatenated =
Z_LVAL_PP(tmpzval);
+ zval_ptr_dtor(tmpzval);
+ tmpzval = NULL;
+ }
+
zend_hash_find(HASH_OF(filterparams), "small",
sizeof("small"), (void **) &tmpzval);
} else {
tmpzval = &filterparams;
@@ -321,12 +368,12 @@
if (tmpzval) {
SEPARATE_ZVAL(tmpzval);
convert_to_boolean_ex(tmpzval);
- smallFootprint = Z_LVAL_PP(tmpzval);
+ data->small_footprint = Z_LVAL_PP(tmpzval);
zval_ptr_dtor(tmpzval);
}
}
- status = BZ2_bzDecompressInit(&(data->strm), 0, smallFootprint);
+ data->status = PHP_BZ2_UNITIALIZED;
fops = &php_bz2_decompress_ops;
} else if (strcasecmp(filtername, "bzip2.compress") == 0) {
int blockSize100k = PHP_BZ2_FILTER_DEFAULT_BLOCKSIZE;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php