changeset 11:b12d2ee20755

Gunzip: fix gunzip of empty gzip stream. Reported by: Matthieu Tourne
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 07 Mar 2010 17:05:43 +0300
parents e60753404354
children 5b45458fb4ac
files ngx_http_gunzip_filter_module.c t/gunzip.t
diffstat 2 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ngx_http_gunzip_filter_module.c
+++ b/ngx_http_gunzip_filter_module.c
@@ -537,23 +537,18 @@ ngx_http_gunzip_filter_inflate(ngx_http_
 
     if (ctx->in == NULL) {
 
+        b = ctx->out_buf;
+
+        if (ngx_buf_size(b) == 0) {
+            return NGX_OK;
+        }
+
         cl = ngx_alloc_chain_link(r->pool);
         if (cl == NULL) {
             return NGX_ERROR;
         }
 
-        b = ctx->out_buf;
-
-        if (ngx_buf_size(b) == 0) {
-
-            b = ngx_calloc_buf(ctx->request->pool);
-            if (b == NULL) {
-                return NGX_ERROR;
-            }
-
-        } else {
-            ctx->zstream.avail_out = 0;
-        }
+        ctx->zstream.avail_out = 0;
 
         cl->buf = b;
         cl->next = NULL;
--- a/t/gunzip.t
+++ b/t/gunzip.t
@@ -20,7 +20,7 @@ select STDOUT; $| = 1;
 eval { require IO::Compress::Gzip; };
 Test::More::plan(skip_all => "IO::Compress::Gzip not found") if $@;
 
-my $t = Test::Nginx->new()->has(qw/http proxy gzip_static/)->plan(12);
+my $t = Test::Nginx->new()->has(qw/http proxy gzip_static/)->plan(13);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -77,6 +77,12 @@ IO::Compress::Gzip::gzip(\$in => \$out);
 $t->write_file('t2.gz', $out . $out);
 $t->write_file('t3', 'not compressed');
 
+my $emptyin = '';
+my $emptyout;
+IO::Compress::Gzip::gzip(\$emptyin => \$emptyout);
+
+$t->write_file('empty.gz', $emptyout);
+
 $t->run();
 
 ###############################################################################
@@ -102,4 +108,6 @@ like(http_head('/t1'), qr/Vary/, 'head v
 unlike(http_get('/t3'), qr/Vary/, 'no vary on non-gzipped get');
 unlike(http_head('/t3'), qr/Vary/, 'no vary on non-gzipped head');
 
+like(http_get('/empty'), qr/ 200 /, 'gunzip empty');
+
 ###############################################################################