]> git.kaiwu.me - nginx.git/commitdiff
Image filter: large image handling.
authorLanshun Zhou <zls.sogou@gmail.com>
Tue, 27 Aug 2013 16:19:07 +0000 (00:19 +0800)
committerLanshun Zhou <zls.sogou@gmail.com>
Tue, 27 Aug 2013 16:19:07 +0000 (00:19 +0800)
If Content-Length header is not set, and the image size is larger than the
buffer size, client will hang until a timeout occurs.

Now NGX_HTTP_UNSUPPORTED_MEDIA_TYPE is returned immediately.

diff -r d1403de41631 -r 4fae04f332b4
src/http/modules/ngx_http_image_filter_module.c

src/http/modules/ngx_http_image_filter_module.c

index 6d3f47dcbf56c360496dfe73fdbb1db551221ff3..cc41ef0d50f341e332d3f756c924c76befd4be38 100644 (file)
@@ -478,7 +478,12 @@ ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in)
                        "image buf: %uz", size);
 
         rest = ctx->image + ctx->length - p;
-        size = (rest < size) ? rest : size;
+
+        if (size > rest) {
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                          "image filter: too big response");
+            return NGX_ERROR;
+        }
 
         p = ngx_cpymem(p, b->pos, size);
         b->pos += size;