[PHP-CVS] cvs: php-src /ext/bz2 bz2_filter.c /ext/zlib zlib_filter.c

2008-10-11 Thread Greg Beaver
cellog  Sat Oct 11 19:14:48 2008 UTC

  Modified files:  
/php-src/ext/zlib   zlib_filter.c 
/php-src/ext/bz2bz2_filter.c 
  Log:
  MFB fix Bug #46026: bz2.decompress/zlib.inflate filter tries to decompress 
after end of stream
  MFB add concatenation option to bz2.decompress stream filter
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib_filter.c?r1=1.23r2=1.24diff_format=u
Index: php-src/ext/zlib/zlib_filter.c
diff -u php-src/ext/zlib/zlib_filter.c:1.23 php-src/ext/zlib/zlib_filter.c:1.24
--- php-src/ext/zlib/zlib_filter.c:1.23 Tue Feb 12 23:27:46 2008
+++ php-src/ext/zlib/zlib_filter.c  Sat Oct 11 19:14:47 2008
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: zlib_filter.c,v 1.23 2008/02/12 23:27:46 cellog Exp $ */
+/* $Id: zlib_filter.c,v 1.24 2008/10/11 19:14:47 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;
 
 /* }}} */
@@ -88,6 +89,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;
@@ -96,7 +103,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;
@@ -125,7 +135,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) {
@@ -153,7 +163,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);
@@ -347,6 +359,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.17r2=1.18diff_format=u
Index: php-src/ext/bz2/bz2_filter.c
diff -u php-src/ext/bz2/bz2_filter.c:1.17 php-src/ext/bz2/bz2_filter.c:1.18
--- php-src/ext/bz2/bz2_filter.c:1.17   Sat Jan 12 22:03:44 2008
+++ php-src/ext/bz2/bz2_filter.cSat Oct 11 19:14:48 2008
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: bz2_filter.c,v 1.17 2008/01/12 22:03:44 cellog Exp $ */
+/* $Id: bz2_filter.c,v 1.18 2008/10/11 19:14:48 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;
 
 /* }}} */
@@ -89,6 +100,21 @@
 
bucket = php_stream_bucket_make_writeable(bucket 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 

[PHP-CVS] cvs: php-src /ext/bz2 bz2_filter.c /ext/zlib zlib_filter.c

2008-01-12 Thread Greg Beaver
cellog  Sat Jan 12 22:03:44 2008 UTC

  Modified files:  
/php-src/ext/zlib   zlib_filter.c 
/php-src/ext/bz2bz2_filter.c 
  Log:
  MFB: far better fix for bug #40189
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib_filter.c?r1=1.20r2=1.21diff_format=u
Index: php-src/ext/zlib/zlib_filter.c
diff -u php-src/ext/zlib/zlib_filter.c:1.20 php-src/ext/zlib/zlib_filter.c:1.21
--- php-src/ext/zlib/zlib_filter.c:1.20 Sat Jan 12 21:25:43 2008
+++ php-src/ext/zlib/zlib_filter.c  Sat Jan 12 22:03:44 2008
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: zlib_filter.c,v 1.20 2008/01/12 21:25:43 cellog Exp $ */
+/* $Id: zlib_filter.c,v 1.21 2008/01/12 22:03:44 cellog Exp $ */
 
 #include php.h
 #include php_zlib.h
@@ -114,11 +114,9 @@
data-strm.avail_out = data-outbuf_len;
data-strm.next_out = data-outbuf;
exit_status = PSFS_PASS_ON;
-   if (status == Z_STREAM_END) {
+   if (status == Z_STREAM_END  
data-strm.avail_out = data-outbuf_len) {
/* no more data to decompress, and 
nothing was spat out */
-   if (data-strm.avail_out = 
data-outbuf_len) {
-   php_stream_bucket_delref(bucket 
TSRMLS_CC);
-   }
+   php_stream_bucket_delref(bucket 
TSRMLS_CC);
return PSFS_PASS_ON;
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/bz2_filter.c?r1=1.16r2=1.17diff_format=u
Index: php-src/ext/bz2/bz2_filter.c
diff -u php-src/ext/bz2/bz2_filter.c:1.16 php-src/ext/bz2/bz2_filter.c:1.17
--- php-src/ext/bz2/bz2_filter.c:1.16   Sat Jan 12 21:25:42 2008
+++ php-src/ext/bz2/bz2_filter.cSat Jan 12 22:03:44 2008
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: bz2_filter.c,v 1.16 2008/01/12 21:25:42 cellog Exp $ */
+/* $Id: bz2_filter.c,v 1.17 2008/01/12 22:03:44 cellog Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -108,7 +108,7 @@
consumed += desired;
bin += desired;
 
-   if (status == BZ_STREAM_END || data-strm.avail_out  
data-outbuf_len) {
+   if (data-strm.avail_out  data-outbuf_len) {
php_stream_bucket *out_bucket;
size_t bucketlen = data-outbuf_len - 
data-strm.avail_out;
out_bucket = php_stream_bucket_new(stream, 
estrndup(data-outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC);
@@ -116,13 +116,10 @@
data-strm.avail_out = data-outbuf_len;
data-strm.next_out = data-outbuf;
exit_status = PSFS_PASS_ON;
-   if (status == BZ_STREAM_END) {
-   /* no more data to decompress, and 
nothing was spat out */
-   if (data-strm.avail_out = 
data-outbuf_len) {
-   php_stream_bucket_delref(bucket 
TSRMLS_CC);
-   }
-   return PSFS_PASS_ON;
-   }
+   } else if (status == BZ_STREAM_END  
data-strm.avail_out = data-outbuf_len) {
+   /* no more data to decompress, and nothing was 
spat out */
+   php_stream_bucket_delref(bucket TSRMLS_CC);
+   return PSFS_PASS_ON;
}
}
php_stream_bucket_delref(bucket TSRMLS_CC);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/bz2 bz2_filter.c /ext/zlib zlib_filter.c

2007-01-25 Thread Antony Dovgal
tony2001Thu Jan 25 12:21:24 2007 UTC

  Modified files:  
/php-src/ext/bz2bz2_filter.c 
/php-src/ext/zlib   zlib_filter.c 
  Log:
  fix #40189 (possible endless loop in zlib.inflate stream filter)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/bz2_filter.c?r1=1.11r2=1.12diff_format=u
Index: php-src/ext/bz2/bz2_filter.c
diff -u php-src/ext/bz2/bz2_filter.c:1.11 php-src/ext/bz2/bz2_filter.c:1.12
--- php-src/ext/bz2/bz2_filter.c:1.11   Mon Jan  1 09:29:21 2007
+++ php-src/ext/bz2/bz2_filter.cThu Jan 25 12:21:24 2007
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: bz2_filter.c,v 1.11 2007/01/01 09:29:21 sebastian Exp $ */
+/* $Id: bz2_filter.c,v 1.12 2007/01/25 12:21:24 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -108,6 +108,11 @@
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;
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib_filter.c?r1=1.14r2=1.15diff_format=u
Index: php-src/ext/zlib/zlib_filter.c
diff -u php-src/ext/zlib/zlib_filter.c:1.14 php-src/ext/zlib/zlib_filter.c:1.15
--- php-src/ext/zlib/zlib_filter.c:1.14 Mon Jan  1 09:29:35 2007
+++ php-src/ext/zlib/zlib_filter.c  Thu Jan 25 12:21:24 2007
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: zlib_filter.c,v 1.14 2007/01/01 09:29:35 sebastian Exp $ */
+/* $Id: zlib_filter.c,v 1.15 2007/01/25 12:21:24 tony2001 Exp $ */
 
 #include php.h
 #include php_zlib.h
@@ -106,6 +106,11 @@
data-strm.avail_in = 0;
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;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php