endless loop in zlib.inflate stream filter
| Bug #40189 | endless loop in zlib.inflate stream filter | ||||
|---|---|---|---|---|---|
| Submitted: | 2007-01-22 02:25 UTC | Modified: | 2008-01-12 21:37 UTC | ||
| From: | cellog@php.net | Assigned: | cellog (profile) | ||
| Status: | Closed | Package: | Zlib related | ||
| PHP Version: | 5CVS-2007-01-22 (CVS) | OS: | kubuntu linux | ||
| Private report: | No | CVE-ID: | None | ||
[2007-01-22 02:25 UTC] 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;
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2007-01-22 07:17 UTC] tony2001@php.net
[2007-01-22 08:55 UTC] mike@php.net
[2007-01-22 09:46 UTC] tony2001@php.net
[2007-01-23 23:57 UTC] cellog@php.net
[2007-01-23 23:58 UTC] cellog@php.net
[2007-01-25 12:22 UTC] tony2001@php.net
[2008-01-12 20:03 UTC] cellog@php.net
[2008-01-12 21:37 UTC] cellog@php.net