# HG changeset patch # User Maxim Dounin # Date 1267970743 -10800 # Node ID b12d2ee2075527e5ec98065f9b1faf7c39302fd2 # Parent e607534043542f165269aa48d5d204ff6a919fcc Gunzip: fix gunzip of empty gzip stream. Reported by: Matthieu Tourne diff --git a/ngx_http_gunzip_filter_module.c b/ngx_http_gunzip_filter_module.c --- 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; diff --git a/t/gunzip.t b/t/gunzip.t --- 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'); + ###############################################################################