#40189 [Opn->Asn]: endless loop in zlib.inflate stream filter

From: Date: Mon, 22 Jan 2007 07:17:03 +0000
Subject: #40189 [Opn->Asn]: endless loop in zlib.inflate stream filter
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107856@lists.php.net to get a copy of this message
ID: 40189 Updated by: tony2001@php.net Reported By: cellog@php.net -Status: Open +Status: Assigned Bug Type: Zlib Related Operating System: kubuntu linux PHP Version: 5CVS-2007-01-22 (CVS) -Assigned To: +Assigned To: pollita New Comment: Sara, could you look into this? Btw, I can see the very same code in ext/bz2. Previous Comments: ------------------------------------------------------------------------ [2007-01-22 02:25:51] cellog@php.net Description: ------------ run the test pecl/phar/tests/phar_ctx_001.phpt or pecl/phar/tests/phar_oo_compressed_001.phpt and you will see an endless loop. The loop happens in ext/zlib/zlib_filter.c at line 83: while (bin < bucket->buflen) { desired = bucket->buflen - bin; if (desired > data->inbuf_len) { desired = data->inbuf_len; } memcpy(data->strm.next_in, bucket->buf + bin, desired); 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) { /* Something bad happened */ php_stream_bucket_delref(bucket TSRMLS_CC); return PSFS_ERR_FATAL; } desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; consumed += desired; bin += desired; 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); php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } the loop should exit when desired is set to 0, but doesn't. The attached patch fixes this issue. Reproduce code: --------------- Index: ext/zlib/zlib_filter.c =================================================================== RCS file: /repository/php-src/ext/zlib/zlib_filter.c,v retrieving revision 1.6.2.2.2.3 diff -u -r1.6.2.2.2.3 zlib_filter.c --- ext/zlib/zlib_filter.c 1 Jan 2007 09:36:10 -0000 1.6.2.2.2.3 +++ ext/zlib/zlib_filter.c 22 Jan 2007 02:23:39 -0000 @@ -99,6 +99,10 @@ data->strm.avail_in = 0; 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; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40189&edit=1

« previous php.bugs (#107856) next »