]> git.kaiwu.me - nginx.git/commitdiff
Gunzip: proper error handling on gunzipping an empty response.
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 31 Oct 2013 00:16:20 +0000 (04:16 +0400)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 31 Oct 2013 00:16:20 +0000 (04:16 +0400)
With previous code, an empty (malformed) response resulted in a request
finalized without sending anything to a client.

src/http/modules/ngx_http_gunzip_filter_module.c

index 9a1ce41a5dd6eb59c22f73c269b925aa460a9cab..adadc9da6dd56ea89a986fce5c3ee78a670e30d8 100644 (file)
@@ -500,9 +500,13 @@ ngx_http_gunzip_filter_inflate(ngx_http_request_t *r,
         return NGX_OK;
     }
 
-    if (rc == Z_STREAM_END && ctx->flush == Z_FINISH
-        && ctx->zstream.avail_in == 0)
-    {
+    if (ctx->flush == Z_FINISH && ctx->zstream.avail_in == 0) {
+
+        if (rc != Z_STREAM_END) {
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                          "inflate() returned %d on response end", rc);
+            return NGX_ERROR;
+        }
 
         if (ngx_http_gunzip_filter_inflate_end(r, ctx) != NGX_OK) {
             return NGX_ERROR;