Opened 4 years ago

Last modified 4 years ago

#756 accepted defect

Client disconnect in ngx_http_image_filter_module

Reported by: www.google.com/accounts/o8/id?id=AItOawlhEma19e0bHTr3V6bh0uDWI70axCbB5i0 Owned by:
Priority: minor Milestone:
Component: nginx-module Version:
Keywords: image_filter module tcp fragmentation client disconnect Cc:
uname -a: Linux XXX.com 3.2.0-65-virtual #99-Ubuntu SMP Fri Jul 4 21:23:03 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.8.0 built with OpenSSL 1.0.1 14 Mar 2012 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/usr/local/src/nginx/debian/modules/nginx-auth-pam --add-module=/usr/local/src/nginx/debian/modules/nginx-dav-ext-module --add-module=/usr/local/src/nginx/debian/modules/nginx-echo --add-module=/usr/local/src/nginx/debian/modules/nginx-upstream-fair --add-module=/usr/local/src/nginx/debian/modules/nginx-pagespeed --add-module=/usr/local/src/nginx/debian/modules/ngx_http_substitutions_filter_module

Description

I have encountered a bug in ngx_http_image_filter_module when used in conjunction with ngx_http_proxy_module ; the configuration is as following:

location /img/ {

proxy_pass http://mybucket.s3.amazonaws.com;
image_filter resize 150 100;

}

The steps to reproduce are rather complicated as they depend on how TCP fragments the response coming from the proxy:

  • If http://mybucket.s3.amazonaws.com returns, in the first TCP packet, a small amount of data (HTTP header, or HTTP header + a few bytes), the content is marked as not an image and NGX_HTTP_UNSUPPORTED_MEDIA_TYPE is returned (disconnecting the client), irrespective on whether or not subsequent data would complete the response to a valid image.

Nginx appears to give up right away on waiting for data if the contents of the first TCP packet received from the proxy does not contain a valid image header- i.e. ngx_http_image_test() will return NGX_HTTP_IMAGE_SIZE, etc.

In my experience this was triggered by a subtle change in AWS S3 that introduced further fragmentation of the TCP responses.

Versions affected: 1.6.2, 1.6.3, 1.7.2, 1.8.0, etc. (all?)

Attaching a 1.8.0 patch that resolves it; the other versions can be fixed similarly.

I think a better fix would be to "return NGX_OK" if we do not have enough data in "case NGX_HTTP_IMAGE_START", and "return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE" (as per the original code) if enough data has been read, but it’s really not an image- but this exceeds the scope of the fix and my use case.

nginx-devel thread: http://mailman.nginx.org/pipermail/nginx-devel/2015-April/006876.html

Attachments (1)

nginx-1.8.0.greedy-image.patch (776 bytes) - added by www.google.com/accounts/o8/id?id=AItOawlhEma19e0bHTr3V6bh0uDWI70axCbB5i0 4 years ago.

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by www.google.com/accounts/o8/id?id=AItOawlhEma19e0bHTr3V6bh0uDWI70axCbB5i0

comment:1 Changed 4 years ago by mdounin

  • Status changed from new to accepted
Note: See TracTickets for help on using tickets.