Klaus Demo nginx / 39c4042
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 reset b->temporary flag in this case. Additionally, an optimization added to avoid allocating additional buffer in this case, by checking if last deflate() call returned Z_STREAM_END. Note that checking for Z_STREAM_END by itself is not enough to fix alerts, as deflate() can return Z_STREAM_END without producing any output if the buffer is smaller than gzip trailer. Reported by Witold Filipczyk, http://mailman.nginx.org/pipermail/nginx-devel/2019-July/012469.html. Maxim Dounin 2 years ago
1 changed file(s) with 11 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
777777
778778 ctx->out_buf->last = ctx->zstream.next_out;
779779
780 if (ctx->zstream.avail_out == 0) {
780 if (ctx->zstream.avail_out == 0 && rc != Z_STREAM_END) {
781781
782782 /* zlib wants to output some more gzipped data */
783783
867867 ngx_http_gzip_ctx_t *ctx)
868868 {
869869 int rc;
870 ngx_buf_t *b;
870871 ngx_chain_t *cl;
871872
872873 ctx->zin = ctx->zstream.total_in;
887888 return NGX_ERROR;
888889 }
889890
890 cl->buf = ctx->out_buf;
891 b = ctx->out_buf;
892
893 if (ngx_buf_size(b) == 0) {
894 b->temporary = 0;
895 }
896
897 b->last_buf = 1;
898
899 cl->buf = b;
891900 cl->next = NULL;
892901 *ctx->last_out = cl;
893902 ctx->last_out = &cl->next;
894
895 ctx->out_buf->last_buf = 1;
896903
897904 ctx->zstream.avail_in = 0;
898905 ctx->zstream.avail_out = 0;