zero size buf in writer in 1.17.2

Maxim Dounin mdounin at mdounin.ru
Mon Jul 29 16:48:41 UTC 2019


Hello!

On Sun, Jul 28, 2019 at 04:32:18PM +0200, Witold Filipczyk wrote:

> Hi,
> There is error in log:
> 2019/07/28 09:46:10 [alert] 2471467#2471467: *407 zero size buf in writer t:1 r:1 f:0 00007F482A259000 00007F482A259000-00007F482A259000 0000000000000000 0-0 while sending response to client, client: 127.0.0.1, server: localhost, request: "GET /Skrypty-m.js HTTP/1.1", host: "localhost"
> 
> Reproducible at least on two machines.

[...]

> Skrypty-m.js in the attachment.
> The error does not occur in 1.17.1 and earlier.

Thank you for the report, it seems to be a problem introduced in 
ac5a741d39cf.  I'm able to reproduce it with the file and gzip 
configuration provided.

The following patch should fix this:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1564415524 -10800
#      Mon Jul 29 18:52:04 2019 +0300
# Node ID aff4d33c72d8ee1a986d3e4c8e5c0f3d1b20962f
# Parent  e7181cfe9212de7f67df805bb746519c059b490b
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.

After ac5a741d39cf it is now possible that after zstream.avail_out
reaches 0 and we allocate additional buffer, there will be no more data
to put into this buffer, triggering "zero size buf" alert.

Fix is to avoid allocating additional buffer in this case, by checking
if last deflate() call returned Z_STREAM_END.

diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -778,7 +778,7 @@ ngx_http_gzip_filter_deflate(ngx_http_re
 
     ctx->out_buf->last = ctx->zstream.next_out;
 
-    if (ctx->zstream.avail_out == 0) {
+    if (ctx->zstream.avail_out == 0 && rc != Z_STREAM_END) {
 
         /* zlib wants to output some more gzipped data */
 

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list